Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VLOOKUP & variable worksheet names

I am using a VLOOKUP function in my macro, which calls upon a workbook
called "master.xls" and a worksheet called "Worksheet ABC" as follows:

ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC4,'[master file.xls]Worksheet
ABC'!R2C1:R65536C7,7,FALSE)"

However, I am trying to avoid hard-coding the workbook name and the
worksheet name in the VLOOKUP formula. I was thinking about using
variables for the workbook and worksheet name (which would be assigned
different values as my macro iterates through a loop), but I'm not sure
what the code would look like using the VLOOKUP function.

Does anyone know how I might generalize this script to avoid hardcoding
the workbook and worksheet names above? My apologies if the question
is too elementary.

Thanks in advance to the kind soul willing to help out!!

-Paul



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default VLOOKUP & variable worksheet names

sBk = "master file.xls"
sSh = "WorksheetABC"

ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC4,'[" & sBk & "]" & _
sSh & "'!R2C1:R65536C7,7,FALSE)"

--
Regards,
Tom Ogilvy


"Paul Kendall" wrote in message
...
I am using a VLOOKUP function in my macro, which calls upon a workbook
called "master.xls" and a worksheet called "Worksheet ABC" as follows:

ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC4,'[master file.xls]Worksheet
ABC'!R2C1:R65536C7,7,FALSE)"

However, I am trying to avoid hard-coding the workbook name and the
worksheet name in the VLOOKUP formula. I was thinking about using
variables for the workbook and worksheet name (which would be assigned
different values as my macro iterates through a loop), but I'm not sure
what the code would look like using the VLOOKUP function.

Does anyone know how I might generalize this script to avoid hardcoding
the workbook and worksheet names above? My apologies if the question
is too elementary.

Thanks in advance to the kind soul willing to help out!!

-Paul



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VLOOKUP & variable worksheet names

Thanks!! I really appreciate your help.



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/

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
Variable Worksheet Names Karen53 Excel Worksheet Functions 4 August 28th 07 01:12 PM
variable file names Brettjg Excel Discussion (Misc queries) 2 March 2nd 07 10:56 AM
Vlookup with variable worksheet reference trempnvt Excel Worksheet Functions 6 May 23rd 06 06:47 PM
Variable Names in Formulas Paulo Excel Discussion (Misc queries) 2 March 29th 06 01:16 PM
Variable Control Names Garry Jones Excel Programming 4 October 3rd 03 10:45 PM


All times are GMT +1. The time now is 05:41 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"