Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
jat jat is offline
external usenet poster
 
Posts: 33
Default vlookup on different sheet/tab based on stored variable

good day,

need help with indirect vlookup formula that i cannot figure out.

File1 is where the macro runs and has several tabs (Sheet1, CLI, COM);
macro button runs from Sheet 1. i use it to import a flatfile or a textfile
to generate orders. when the macro runs, it opens the flat file "File2",
starts to format the file so that i can use it in excel and i have it save
the supplier code in a variable from this - SupCode = Range("B4").Value
- in this example, the SupCode holds the value. (when the macro stops
later, i can go into the code, and hold the cursor over the SupCode and it
shows "CLI")


the extra rows and columns are removed and i am left with an item number,
quantities, and prices. what i want to do is do a vlookup formula that will
be in File2 to lookup a price in File1, with the Sheet being the stored value
in SupCode. in this example File1 and the tab being CLI;

the followign formula works
=VLOOKUP(A3,'[Order Generator.xlsm]CLI'!$B:$D,3,FALSE)
works but i want to automate the CLI portion to be dependant on SupCode.

any ideas?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default vlookup on different sheet/tab based on stored variable

jat,

Do you want a cell with a formula?

ActiveCell.Formula = "=VLOOKUP(A3,'[Order Generator.xlsm]" & SupCode & "'!$B:$D,3,FALSE)"

HTH,
Bernie
MS Excel MVP


"jat" wrote in message
...
good day,

need help with indirect vlookup formula that i cannot figure out.

File1 is where the macro runs and has several tabs (Sheet1, CLI, COM);
macro button runs from Sheet 1. i use it to import a flatfile or a textfile
to generate orders. when the macro runs, it opens the flat file "File2",
starts to format the file so that i can use it in excel and i have it save
the supplier code in a variable from this - SupCode = Range("B4").Value
- in this example, the SupCode holds the value. (when the macro stops
later, i can go into the code, and hold the cursor over the SupCode and it
shows "CLI")


the extra rows and columns are removed and i am left with an item number,
quantities, and prices. what i want to do is do a vlookup formula that will
be in File2 to lookup a price in File1, with the Sheet being the stored value
in SupCode. in this example File1 and the tab being CLI;

the followign formula works
=VLOOKUP(A3,'[Order Generator.xlsm]CLI'!$B:$D,3,FALSE)
works but i want to automate the CLI portion to be dependant on SupCode.

any ideas?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default vlookup on different sheet/tab based on stored variable

this is similar to the concatenate question posted a little later by KG Old
Wolf

use the INDIRECT function and concatenate the texts
so break the formula into bits, you'll see from the following ...

=VLOOKUP(A3,'[Order Generator.xlsm]CLI'!$B:$D,3,FALSE)
=VLOOKUP(A3,INDIRECT("'[Order Generator.xlsm]CLI'!$B:$D"),3,FALSE)
=VLOOKUP(A3,INDIRECT("'[Order Generator.xlsm]" & "CLI" & "'!$B:$D"),3,FALSE)

B1 := CLI
=VLOOKUP(A3,INDIRECT("'[Order Generator.xlsm]" & B1 & "'!$B:$D"),3,FALSE)








"jat" wrote:

good day,

need help with indirect vlookup formula that i cannot figure out.

File1 is where the macro runs and has several tabs (Sheet1, CLI, COM);
macro button runs from Sheet 1. i use it to import a flatfile or a textfile
to generate orders. when the macro runs, it opens the flat file "File2",
starts to format the file so that i can use it in excel and i have it save
the supplier code in a variable from this - SupCode = Range("B4").Value
- in this example, the SupCode holds the value. (when the macro stops
later, i can go into the code, and hold the cursor over the SupCode and it
shows "CLI")


the extra rows and columns are removed and i am left with an item number,
quantities, and prices. what i want to do is do a vlookup formula that will
be in File2 to lookup a price in File1, with the Sheet being the stored value
in SupCode. in this example File1 and the tab being CLI;

the followign formula works
=VLOOKUP(A3,'[Order Generator.xlsm]CLI'!$B:$D,3,FALSE)
works but i want to automate the CLI portion to be dependant on SupCode.

any ideas?

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
XL2002 - VLOOKUP with variable Sheet Name Trevor Williams Excel Worksheet Functions 3 July 29th 08 05:33 PM
set a variable based on a vlookup Debbie Horner Excel Discussion (Misc queries) 5 July 16th 08 06:16 PM
Macro with vlookup with variable sheet stuck4once Excel Programming 5 January 23rd 08 01:12 AM
Copy rows to new sheet based on variable cell reference michaelberrier Excel Programming 1 December 26th 06 04:21 PM
Sheet scroll based on variable Biff Excel Programming 3 September 6th 05 10:30 PM


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