M
MichaelDavid
Greetings! I opened a new blank workbook, and entered the following values in
Column A:
[A1] = 0
[A2] = 1
[A3] = 2
[A4] = 3
I then executed the following subroutine:
Sub Start()
[C1] = 0
Range("C2:C4").FormulaR1C1 = "=R[-1]C+RC[-2]"
MsgBox "C4 =" & [C4] ' As expected, MsgBox displays C4
= 6
' I then tried:
[E1] = 0
Range("E2:E4").Formula = "=E1+A2"
MsgBox "E4 =" & [E4] ' As expected, MsgBox displays E4
= 6
' I now give names to two ranges
Range("G2:G4").Name = "GValues"
Range("A2:A4").Name = "AValues"
[G1] = 0
Range("GValues").Formula = "=AValues+G1"
MsgBox "G4 =" & Range("GValues")(3) ' As expected, MsgBox displays
G4 = 6
' But if I try to assign a name to G1 as follows:
Range("G1").Name = "GInitVal"
' and use it in a formula as follows:
Range("GValues").Formula = "=AValues+GInitVal"
MsgBox "G4 =" & Range("G4")
' [G4] is only 3, not 6 as expected
' How can I name Range G1 so that I get the correct result?
End Sub
--
May you have a most blessed day!
Sincerely,
Michael Fitzpatrick
Column A:
[A1] = 0
[A2] = 1
[A3] = 2
[A4] = 3
I then executed the following subroutine:
Sub Start()
[C1] = 0
Range("C2:C4").FormulaR1C1 = "=R[-1]C+RC[-2]"
MsgBox "C4 =" & [C4] ' As expected, MsgBox displays C4
= 6
' I then tried:
[E1] = 0
Range("E2:E4").Formula = "=E1+A2"
MsgBox "E4 =" & [E4] ' As expected, MsgBox displays E4
= 6
' I now give names to two ranges
Range("G2:G4").Name = "GValues"
Range("A2:A4").Name = "AValues"
[G1] = 0
Range("GValues").Formula = "=AValues+G1"
MsgBox "G4 =" & Range("GValues")(3) ' As expected, MsgBox displays
G4 = 6
' But if I try to assign a name to G1 as follows:
Range("G1").Name = "GInitVal"
' and use it in a formula as follows:
Range("GValues").Formula = "=AValues+GInitVal"
MsgBox "G4 =" & Range("G4")
' [G4] is only 3, not 6 as expected
' How can I name Range G1 so that I get the correct result?
End Sub
--
May you have a most blessed day!
Sincerely,
Michael Fitzpatrick