Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Variable reference

I am tyring to put a value in a cell using the
Activecell.formular1c1 function. Through code I get two
cell values and store them in variables. I then try to
use those two variables in the Activecell.formular1c1
function and it doesn't seem to recognize them as
variables.

CODE:

Cells.Find(What:="Illinois", After:=ActiveCell, _
LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows,_
SearchDirection:=xlNext, MatchCase:=False).Activate
With Selection
.Offset(2, 2).Select
End With

a = Selection.Address

Cells.Find(What:="INDIANA", After:=ActiveCell, _
LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows,_
SearchDirection:=xlNext, MatchCase:=False).Activate
With Selection
.Offset(-1, 2).Select
End With

b = Selection.Address

Range("A1").Select
ActiveCell.FormulaR1C1 = "=Sum(a:b)"

When I run this code Cell A1 has #NAME? in it because
instead of Excel references a and b as their variable
values, they are just recognized as letters.

What do I need to do in order to get those variables in a
format that will actually take the cell that variable
references?

Thanks,
John
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Variable reference

Range("A1").Select
ActiveCell.Formula = "=Sum(" & a & ":" & b & ")"


Should work.

Regards,
Tom Ogilvy

"John" wrote in message
...
I am tyring to put a value in a cell using the
Activecell.formular1c1 function. Through code I get two
cell values and store them in variables. I then try to
use those two variables in the Activecell.formular1c1
function and it doesn't seem to recognize them as
variables.

CODE:

Cells.Find(What:="Illinois", After:=ActiveCell, _
LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows,_
SearchDirection:=xlNext, MatchCase:=False).Activate
With Selection
.Offset(2, 2).Select
End With

a = Selection.Address

Cells.Find(What:="INDIANA", After:=ActiveCell, _
LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows,_
SearchDirection:=xlNext, MatchCase:=False).Activate
With Selection
.Offset(-1, 2).Select
End With

b = Selection.Address

Range("A1").Select
ActiveCell.FormulaR1C1 = "=Sum(a:b)"

When I run this code Cell A1 has #NAME? in it because
instead of Excel references a and b as their variable
values, they are just recognized as letters.

What do I need to do in order to get those variables in a
format that will actually take the cell that variable
references?

Thanks,
John



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
Using variable for cell reference bmurlidhar Excel Discussion (Misc queries) 3 July 17th 09 07:16 AM
How to use variable in reference Ming Excel Worksheet Functions 2 July 27th 05 11:24 PM
How do I use a variable in a cell reference? jsp377 Excel Discussion (Misc queries) 3 January 27th 05 01:43 PM
Problem with =sum(offset(cell reference,w,x,y,z). I want cell reference to be variable [email protected] Excel Worksheet Functions 2 December 11th 04 12:00 AM
Using a variable as a row reference? mjmorrison Excel Programming 2 July 14th 03 07:51 PM


All times are GMT +1. The time now is 07:20 AM.

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"