Excel 97 Worksheet with Macros for
(1) Making a table of function values for one or two functions
(2) Drawing the graph of one or two functions
(3) Solving an equation approximately

Click on blank.xls to download the worksheet. Press Alt F8 to bring
up the macro dialog box.

To make a table of function values for a given function (or two given functions) on a specified interval, run the SetUp macro and follow the instructions. To graph the table, use the Graph macro. To solve an equation approximately, use the Solve macro

You can adjust the height and width of the graph, by clicking on it and dragging the adjusting tabs on the border of graph box. To zoom in or out, change the numbers in the cells R5C3 and R5C4 as desired. The graph will be redrawn according to the new specifications.

To solve an equation f(x)=0, type f(x) in cell R3C2 using R3C1 as the variable x before running the macro Solve. The solution is displayed in cell R3C1.

The text between the two dotted lines below contains the Visual Basic
Code for five Excel 97 macros. The names of the macros are SetUp(), FillData(), Graph(),ClearData() and Solve(). Select the text between the dotted lines and copy and paste to your text editor. Save the file as excelmacros.bas
Open an Excel spreadsheet and choose Tools/Macros/Visual Basic Editor.
In the Visual Basic Editor, choose File/Import to import the
excelmacros.bas text file. If you close the Visual Basic Editor and return to the spreadsheet and hit Alt F8, you will see a dialog box with the above three macros available for your use
 
 


Visual Basic Code


 






------------------------------------------------------------------------- Sub SetUp()
'
' SetUp() Macro
'
'

'
    Range("a1").Formula = "Table Making and Graphing Utility "
    Range("a2").Formula = "Type the left and right ends of the interval in cells C5 and D5"
    Range("a3").Formula = "Type the functions in cells C7 and D7. After that, run the FillData and Graph macros"
    Range("C4").Formula = "Left End "
    Range("D4").Formula = "Right End"
    Range("C6").Formula = "Function 1"
    Range("D6").Formula = "Function 2"
End Sub

Sub FillData()
'
' FillData() Macro
'
'

'
    Range("A5").Formula = "Point #"
    Range("B6").Formula = "X Value"
    Range("A7").Formula = "=R[-1]C+1"
    Range("a7:a27").FillDown
    Range("b7").Formula = "=R5C3+(RC[-1]-1)*(R5C4-R5C3)/20"
    Range("b7:D27").FillDown
End Sub
Sub ClearData()
'
' ClearData Macro
'
'

'
    Range("C5:D5").ClearContents
    Range("A7:D27").ClearContents

End Sub
Sub Graph()
'
' Graph Macro
'
'

'
    Charts.Add
    ActiveChart.ChartType = xlXYScatterSmoothNoMarkers
    ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("C31")
    ActiveChart.SeriesCollection.NewSeries
    ActiveChart.SeriesCollection.NewSeries
    ActiveChart.SeriesCollection(1).XValues = "=Sheet1!R7C2:R27C2"
    ActiveChart.SeriesCollection(1).Values = "=Sheet1!R7C3:R27C3"
    ActiveChart.SeriesCollection(2).XValues = "=Sheet1!R7C2:R27C2"
    ActiveChart.SeriesCollection(2).Values = "=Sheet1!R7C4:R27C4"
    ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
    ActiveChart.Legend.Delete
End Sub
Sub Solve()
'
' Solve Macro
'
'

'
    Range("B3").GoalSeek Goal:=0, ChangingCell:=Range("A3")

End Sub
 

-------------------------------------------------------------------------