ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   vlookup using a variable (https://www.excelbanter.com/excel-programming/310074-re-vlookup-using-variable.html)

Tom Ogilvy

vlookup using a variable
 
ActiveCell.FormulaR1C1 = _
"=VLOOKUP (RC[-67], '" & _
TwoMonthsAgo & "'!C[-67],68,FALSE)"

--
Regards,
Tom Ogilvy

"Tony" wrote in message
...
When I run my macro it opens a file and inserts a new sheet named with the
month and year for last month "Aug04". In this sheet I want to do a

vlookup
into the previous months sheet for some information. I have a variable set

to
store the previous month and year but I am not sure how to use this

variable
in my line of code. The way I have it now is as follows:

ActiveCell.FormulaR1C1 = _
"=VLOOKUP (RC[-67], 'Jul04'!C[-67],68,FALSE)"

It works just fine if I specifically say to look at sheet < 'Jul04'

but
I want it to be automated to use my variable < TwoMonthsAgo . Thank you
for any suggestions.




tony

vlookup using a variable
 
Worked like a charm. Thank you!

"Tom Ogilvy" wrote:

ActiveCell.FormulaR1C1 = _
"=VLOOKUP (RC[-67], '" & _
TwoMonthsAgo & "'!C[-67],68,FALSE)"

--
Regards,
Tom Ogilvy

"Tony" wrote in message
...
When I run my macro it opens a file and inserts a new sheet named with the
month and year for last month "Aug04". In this sheet I want to do a

vlookup
into the previous months sheet for some information. I have a variable set

to
store the previous month and year but I am not sure how to use this

variable
in my line of code. The way I have it now is as follows:

ActiveCell.FormulaR1C1 = _
"=VLOOKUP (RC[-67], 'Jul04'!C[-67],68,FALSE)"

It works just fine if I specifically say to look at sheet < 'Jul04'

but
I want it to be automated to use my variable < TwoMonthsAgo . Thank you
for any suggestions.






All times are GMT +1. The time now is 12:22 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com