Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I use values in a formula in VBA 1

Status
Not open for further replies.

Naomi72

Technical User
Apr 24, 2003
5
IE
I'm trying to automate some excel procedures using vba. Currently I'm having difficulties when I need to insert a formula into a cell that takes values such as the row and the sheet name in a file, and passes then into the formula.
SheetName is entered in a form.

MyRow = Selection.Row
Formula1 = "=LOOKUP($A MyRow,'Locationoffile\[Filename]SheetName'!R8C1:R33C1,'Locationoffile\[Filename]SheetName'!R8C5:R33C5)"

Any help, hints etc., would be brilliant.

Thanks
 
Maybe as an alternate....


you could pass the result of the formula directly to the cell



sheets("my_sheet").range("my_cell")=application.worksheetfunction.LOOKUP($A MyRow,'Locationoffile\[Filename]SheetName'!R8C1:R33C1,'Locationoffile\[Filename]SheetName'!R8C5:R33C5)
 
Formula is entered as a string so:

Formula1 = "=LOOKUP($A" & MyRow & ",'Locationoffile\[Filename]SheetName'!R8C1:R33C1,'Locationoffile\[Filename]SheetName'!R8C5:R33C5)"

should work


Rgds
Geoff
"Some cause happiness wherever they go; others whenever they go."
-Oscar Wilde
 
Thanks a million Geoff, that worked fantastically.

Kind Regards

Naomi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top