Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default Unable to name certain ranges

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default Unable to name certain ranges


Hi Michael,

The result is correct. When you look at the formula in G4 you will
see
=AValues+GInitVal

The value of GInitVal is allways 0.
When you use a namedrange and not a celladdress then name will be
constant.

HTH (sort of)

Wouter
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,420
Default Unable to name certain ranges

Why do you expect it to be 6?

A4, which is within AValues, is assigned a value of 3. G1, which is
GInitVal, is assigned a value of 0. 3+0=3. QED.

--
__________________________________
HTH

Bob

"MichaelDavid" wrote in message
...
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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default Unable to name certain ranges

Greetings! Is there any way to give GIntValue a name or define it in such a
way that
Range("GValues").Formula = "=AValues+GInitVal"
would yield a value of 6 for [G4] as was the case in each of the preceding
results?
Or is there any way I can name Range G1 such that it will work in the above
formula to yield a value of 6 for [G4]?
--
May you have a most blessed day!

Sincerely,

Michael Fitzpatrick


"MichaelDavid" wrote:

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable to click on charts & unable to create any new charts Excel Snapclick Charts and Charting in Excel 4 February 1st 09 07:59 PM
Unable to replace cell references with Named ranges lhim2 Excel Discussion (Misc queries) 0 January 28th 08 04:13 PM
Copy data in named ranges to a newer version of the same template to identical ranges handstand Excel Programming 0 August 21st 06 03:51 PM
Protect Sheet but enable cell ranges giving Error 1004 Unable to set William[_4_] Excel Programming 3 August 11th 04 09:09 PM
named ranges - changing ranges with month selected gr8guy Excel Programming 2 May 28th 04 04:50 AM


All times are GMT +1. The time now is 03:45 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"