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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Vlookup using named ranges or variable column #

Status
Not open for further replies.

cboz

Technical User
Dec 24, 2002
42
US
I have the folowing code in a macro:
Range("M2").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC1,MRPDet,8,0)"

The problem is that sometimes the data in not in column 8. It could be in columns 6, 7 or 8. How do I compensate? The named range for the column I want to use is called Sales_Order.
 
cboz,
is there anything that determins what column the data might be in?
regards,
longhair
 
Other than the column heading "Sales_Order", who's location could change from one day to the next, then no. This worksheet is the results of a pivot table. The sheet the pivot table is based on varies as to what is in it each day. This is why the Sales_order column isn't always in column 8.
 
cboz,
you could probably do it in two steps.
first find the column that has the heading "Sales_Order", store the column number (ie 6, 7, or 8) in a var.
use the var in your vlookup.
hth
regards,
longhair
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top