how can I edit the code so that when I use the calculator axis titles will appear, labelling "time" at x-axis and "accumulated value" at y-axis

Ryuuk

New Member
Joined
Jul 10, 2021
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Private Sub Calculator_Click()

Dim Deposit As Single
Dim term As Single
Dim AV As Double
Dim SumAV As Double
Dim Dividend As Double
Dim ProductDividend As Double
Dim SumProductDividend As Double
Dim StartYear As Single
Dim Year As Single
Dim rng As Range
Dim cht As Object

Range("G5:H25").ClearContents

Deposit = TextBox1.Value
term = TextBox2.Value

StartYear = 2000
ProductDividend = 1
t = 0

If term > 21 Then
MsgBox ("Term must be between 0 to 21")

ElseIf term < 0 Then
MsgBox ("Term must be between 0 to 21")

Else
Do
For i = 0 To term - 1

Year = StartYear + i
Dividend = WorksheetFunction.VLookup(Year, Sheet1.Range("$B$4:$C$25"), 2, 0)
ProductDividend = ProductDividend * (1 + Dividend)

Next i

SumProductDividend = SumProductDividend + ProductDividend
AV = Deposit * SumProductDividend
SumAV = SumAV + AV
StartYear = StartYear + 1
term = term - 1
SumProductDividend = 0
ProductDividend = 1

Cells(5 + t, 8) = SumAV
Cells(5 + t, 7) = 2000 + t
t = t + 1
Loop While StartYear <= StartYear + term - 1

'Your data range for the chart
Set rng = ActiveSheet.Range("H4:H25")

'Create a chart
Set cht = ActiveSheet.Shapes.AddChart2

'Give chart some data
cht.Chart.SetSourceData Source:=rng

'Determine the chart type
cht.Chart.ChartType = xlXYScatterLines

'Change chart's title
cht.Chart.ChartTitle.Text = "Accumulated Value Through Time"




End If

End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Perhaps a better option is to create a chart without code and lay it out exactly as you want it, then hide it until the calculation is done

activesheet.chartobjects(1).visible=False ' to hide it
activesheet.chartobjects(1).visible=True 'to show it
 
Upvote 0
Perhaps a better option is to create a chart without code and lay it out exactly as you want it, then hide it until the calculation is done

activesheet.chartobjects(1).visible=False ' to hide it
activesheet.chartobjects(1).visible=True 'to show it
But my assignment ask me to build the calculator for the accumulated value until maximum term 21 and it also put rules to produce the chart along after inserting the random numbers on the calculator
 
Upvote 0
In that case, I would record a macro and then add the axis titles manually, which will give you the code you need
 
Upvote 0
Solution
In that case, I would record a macro and then add the axis titles manually, which will give you the code you need
ok I'll consider that option after me and my team discuss about it. thanks mate
 
Upvote 0

Forum statistics

Threads
1,214,593
Messages
6,120,435
Members
448,962
Latest member
Fenes

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top