Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
hello everybody
i posted earlier about this but i might not have been very clear(mod's can delete the last post if they want), what i want to do is add modules to my spread sheet that would have a program that performs some calculation.(i know i could use a write a formula within the spreadsheet but i would like to do this using code in the module)
what i would like to know is that how would i call a module function(code) as stated above above in the excel spreadsheet??????
and how would i go about calculating a large # of data
any help appreciated, c'mon this can't be too hard!

Read through this and ask if you have more questions:
Functions in modules run by:
1) In response to an events
2) Being called by other functionsEvents include:
1) Opening workbook
2) Clicking a control such as a Command Button
3) Responding to a Timer
=================================================
Excel Workbooks have three major types of objects:
1) Excel Objects
2) Forms
3) Modules1) Excel objects include individual Sheets and the Workbook. Each object has its own code module.
2) Forms are dialog boxes and can have controls added to them. Controls include: Check Boxes, Text Boxes, Command Buttons, Option Buttons, List Boxes, Combo Boxes, Toggle Buttons, Spin Button, Scroll Bar, Labels, and Images. Each form has its own code module.
3) Modules are independent code modules that have no associaed object.
Examples of functions in code modules:
The Sub Workbook_Open() will automatically run when the workbook is opened.
In the example below the Workbook_Open functions does the following:
1) The TestsDialog form is displayedPrivate Sub Workbook_Open()
TestsDialog.show
End Sub
------------------------------------------------------------
The TestsDialog form has buttons on it that so that it acts like a menu.
The TestsDialog form's code module has functions that are activate when
the buttons are clicked on by the mouse.In the example below the AutomaticButton_Click function runs when the button
assocated with it is selected with the mouse. This functions does the following:
1) Hides TestsDialog form
2) Calls function PerformanceTest
3) Shows TestsDialog form upon return from PerformanceTestPrivate Sub AutomaticButton_Click()
TestsDialog.hide
Call PerformanceTest
TestsDialog.show
End Sub
-----------------------------------------------------------
The PerformanceTest function is in independent code module AutomaticTest. This function does the follwing:
1) Read in data from a tab-delimited text file into a new worksheet.
2) Uses data in worksheet in calculations and writes results into new columns
3) Plots results from selected columns using excel's ploting functions
4) Saves Workbook with new worksheets and plots
5) Return to TestsDialog formPublic Sub PerformanceTest()
Dim RecordFile As String, datasheet As String
Const FirstRow As Integer = 2
Dim LastRow As Integer, StartRow As Integer, StartRowErr As Integer, MinVal As Integer
...
RecordFile = GetRecordFileName("Open Performance Data File")
...
LastRow = GetLastRow
StartRow = GetStartRow(RBCol, FirstRow)
MinVal = 33
StartRowErr = GetStartRowVal(Col, FirstRow, MinVal)
Call ShowMessageBox("Performance", "Calculating New Data...")
Call ShowMessageBox("Performance", "Plotting Data")
Call PlotData1(datasheet, StartRow, LastRow, chnCol, _
Col, RngCol, trueRngCol)
CallPlotData2(datasheet, StartRowErr, LastRow, chnCol, _
RngCol, Col, Col1, BCol,ErrCol)
HideMessageBox
Call SaveWorkbook
End SubNote: this function is incomplete because of a requirement to not show sensitive information.

If you're asking what I think you're asking then try the following:
Say you want a function that squares a number and adds thirteen to the result.
We'll call this function "SquareThirteen"
In your Excel spreadsheet, hti Alt + F11 to open the code editor and Insert Module.
Then enter the following:
Function SquareThirteen(numberIn As Double)
SquareThirteen = (numberIn ^ 2) + 13
End Function
Hope that helps - apologies if I've completely missed the point!Tom

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |