Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Kim Kim is offline
external usenet poster
 
Posts: 284
Default Can't reference a named cell in VBA

I've combined two cells to make a named cell. ie. A2 = left three chars of
this month, B2 = wheat. "Apr Wheat" is a named cell. I can't seem to figure
out how to assign the value of named cell "Price" to the named cell "Apr
Wheat" in VB. The code [Apr Wheat].cells.value = [price] works fine, just
can't get a variable that's combined A2 & B2 to work. I'm in Excel 2003.

What can't I see? Thanks for any help.

Kim
  #2   Report Post  
Posted to microsoft.public.excel.programming
Art Art is offline
external usenet poster
 
Posts: 587
Default Can't reference a named cell in VBA

Kim,

You may just be missing a space between your variables.

I named the following ranges:
Apr = A1:A5
Wheat = B3:E3
Rice = B4:E4

The following code will print out the contents of A3:

Sub test()
Dim a As String
Dim b As String
Dim c As String
a = "Apr"
b = "Wheat"
c = "Rice"
MsgBox (Range(a & " " & b))
End Sub

It prints out A4 if you use c instead of b.

"Kim" wrote:

I've combined two cells to make a named cell. ie. A2 = left three chars of
this month, B2 = wheat. "Apr Wheat" is a named cell. I can't seem to figure
out how to assign the value of named cell "Price" to the named cell "Apr
Wheat" in VB. The code [Apr Wheat].cells.value = [price] works fine, just
can't get a variable that's combined A2 & B2 to work. I'm in Excel 2003.

What can't I see? Thanks for any help.

Kim

  #3   Report Post  
Posted to microsoft.public.excel.programming
Kim Kim is offline
external usenet poster
 
Posts: 284
Default Can't reference a named cell in VBA

Art,

My posting error. I'm looking to put the values of the one named cell into
another named cell. The cell names appear to be OK and if I put the named
cell in the code it seems to work OK. It's just when I try to reference the
newly created cell I fail. Maybe this will help:

a1 = April
a2 = Wheat
a3 = left(a1) & " _" & a2

Apr_Wheat is a named cell, located at b1

Price is a named cell, located at c2, it has a value of 3.50

My problem is putting 3.50 in cell b1 using the cell names.

I hope I explained this better. It's more difficult to explain than I
thought.

Thanks for sticking with me.

Kim

"Art" wrote:

Kim,

You may just be missing a space between your variables.

I named the following ranges:
Apr = A1:A5
Wheat = B3:E3
Rice = B4:E4

The following code will print out the contents of A3:

Sub test()
Dim a As String
Dim b As String
Dim c As String
a = "Apr"
b = "Wheat"
c = "Rice"
MsgBox (Range(a & " " & b))
End Sub

It prints out A4 if you use c instead of b.

"Kim" wrote:

I've combined two cells to make a named cell. ie. A2 = left three chars of
this month, B2 = wheat. "Apr Wheat" is a named cell. I can't seem to figure
out how to assign the value of named cell "Price" to the named cell "Apr
Wheat" in VB. The code [Apr Wheat].cells.value = [price] works fine, just
can't get a variable that's combined A2 & B2 to work. I'm in Excel 2003.

What can't I see? Thanks for any help.

Kim

  #4   Report Post  
Posted to microsoft.public.excel.programming
Art Art is offline
external usenet poster
 
Posts: 587
Default Can't reference a named cell in VBA

Kim,

Sorry I misunderstood. Is this what you're looking for?

Sub test()
Range(Range("A3")) = Range("Price")
End Sub

"Kim" wrote:

Art,

My posting error. I'm looking to put the values of the one named cell into
another named cell. The cell names appear to be OK and if I put the named
cell in the code it seems to work OK. It's just when I try to reference the
newly created cell I fail. Maybe this will help:

a1 = April
a2 = Wheat
a3 = left(a1) & " _" & a2

Apr_Wheat is a named cell, located at b1

Price is a named cell, located at c2, it has a value of 3.50

My problem is putting 3.50 in cell b1 using the cell names.

I hope I explained this better. It's more difficult to explain than I
thought.

Thanks for sticking with me.

Kim

"Art" wrote:

Kim,

You may just be missing a space between your variables.

I named the following ranges:
Apr = A1:A5
Wheat = B3:E3
Rice = B4:E4

The following code will print out the contents of A3:

Sub test()
Dim a As String
Dim b As String
Dim c As String
a = "Apr"
b = "Wheat"
c = "Rice"
MsgBox (Range(a & " " & b))
End Sub

It prints out A4 if you use c instead of b.

"Kim" wrote:

I've combined two cells to make a named cell. ie. A2 = left three chars of
this month, B2 = wheat. "Apr Wheat" is a named cell. I can't seem to figure
out how to assign the value of named cell "Price" to the named cell "Apr
Wheat" in VB. The code [Apr Wheat].cells.value = [price] works fine, just
can't get a variable that's combined A2 & B2 to work. I'm in Excel 2003.

What can't I see? Thanks for any help.

Kim

  #5   Report Post  
Posted to microsoft.public.excel.programming
Kim Kim is offline
external usenet poster
 
Posts: 284
Default Can't reference a named cell in VBA

Art,

Works like a champ! Thanks!

Kim

"Art" wrote:

Kim,

Sorry I misunderstood. Is this what you're looking for?

Sub test()
Range(Range("A3")) = Range("Price")
End Sub

"Kim" wrote:

Art,

My posting error. I'm looking to put the values of the one named cell into
another named cell. The cell names appear to be OK and if I put the named
cell in the code it seems to work OK. It's just when I try to reference the
newly created cell I fail. Maybe this will help:

a1 = April
a2 = Wheat
a3 = left(a1) & " _" & a2

Apr_Wheat is a named cell, located at b1

Price is a named cell, located at c2, it has a value of 3.50

My problem is putting 3.50 in cell b1 using the cell names.

I hope I explained this better. It's more difficult to explain than I
thought.

Thanks for sticking with me.

Kim

"Art" wrote:

Kim,

You may just be missing a space between your variables.

I named the following ranges:
Apr = A1:A5
Wheat = B3:E3
Rice = B4:E4

The following code will print out the contents of A3:

Sub test()
Dim a As String
Dim b As String
Dim c As String
a = "Apr"
b = "Wheat"
c = "Rice"
MsgBox (Range(a & " " & b))
End Sub

It prints out A4 if you use c instead of b.

"Kim" wrote:

I've combined two cells to make a named cell. ie. A2 = left three chars of
this month, B2 = wheat. "Apr Wheat" is a named cell. I can't seem to figure
out how to assign the value of named cell "Price" to the named cell "Apr
Wheat" in VB. The code [Apr Wheat].cells.value = [price] works fine, just
can't get a variable that's combined A2 & B2 to work. I'm in Excel 2003.

What can't I see? Thanks for any help.

Kim

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
Reference Column of Named Cell vba Isis[_2_] Excel Discussion (Misc queries) 6 May 3rd 10 01:44 PM
Sheet won't reference a named cell Mike H Excel Worksheet Functions 2 September 9th 09 08:28 PM
Vlookup - using a cell to reference a named array Ronin Excel Worksheet Functions 3 May 14th 08 06:26 PM
reference first cell in a named range Robert H Excel Worksheet Functions 3 January 14th 08 07:53 PM
Named Range reference via single Cell Graham Excel Discussion (Misc queries) 0 July 26th 06 09:37 AM


All times are GMT +1. The time now is 06:16 PM.

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

About Us

"It's about Microsoft Excel"