Friday, 17 March 2023
  0 Replies
  1.5K Visits
0
Votes
Undo
I'm still a fairly novice user of VBA and am very self taught. I'm trying to write a macro that will use a value in one cell to launch a macro which has a formula in another cell. I've got a macro that works however I can't work out how to make it run for a range of cells. Please see below and advise how i can change this so that it triggers for my range O6:O26. I will end up having 7 different formulas that can be selected and would therefore have more if targets equal options in that section. It's the first bit I'd like to change so that I can get it to work for the range rather than just the one cell.
Thank you!

Sub Formula()
'
' Formula Macro
Set target = Range("O6")
If target.Value = "1" Then
Call Macro1
End If
If target.Value = "2" Then
Call Macro2
End If
End Sub

_________________________________________________________________________________________
Sub Macro1()
'
' Macro1 Macro

Range("P6").Select
ActiveCell.FormulaR1C1 = _
"=(1.08)/(0.06+(0.08*(RC[-2])))"
'
End Sub

_____________________________________________________________________________________________
Sub Macro2()
'
' Macro2 Macro
'
Range("P6").Select
ActiveCell.FormulaR1C1 = _
"=(1.06)/(0.08+(0.08*(RC[-2])))"
'
End Sub
There are no replies made for this post yet.