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

Excel 2003 & VBA: VLookup question

Status
Not open for further replies.

davis07

Technical User
Feb 10, 2007
4
US
Hi, I am trying to get the following equation to work. I want the vlookup command to search columns A thru C, but the formula doesn't work as is. I've tried relative references too, but can't get it to work.

ActiveCell.FormulaR1C1 = _
"=IF(RC[5]=""NO"",NOW(),VLOOKUP(TRIM(RC[-15]),OtherSheet!" & "A:C" & ",3,FALSE))"

The above formula yields:
=IF(V2="NO",NOW(),VLOOKUP(TRIM(B2),OtherSheet!A:Q:Q,3,FALSE))

Thanks in advance!
 
How are you getting A:Q:Q? Also, what do you mean by does not work? What error are you getting?

Is your lookup table actually on sheet called othersheet and is the value of b2 in column a of othersheet?


ck1999
 
When I run the VBA program, it runs that line in the code and inserts what I have indicated as 'yields'... I don't know where it is getting the Q:Q. Yes, the look-up value IS in the othersheet (name changed for simplicity). I want it to insert:

=IF(V2="NO",NOW(),VLOOKUP(TRIM(B2),OtherSheet!A:C,3,FALSE))

Any tips?
Thanks in advance.
 
try

"=IF(RC[5]=""NO"",NOW(),VLOOKUP(TRIM(RC[-15]),OtherSheet!A:C,3,FALSE))"


ck1999

 
OtherSheet!A:C is not a valid R1C1 notation.
You may try this:
Code:
ActiveCell.Formula = _
   "=IF(V2=""NO"",NOW(),VLOOKUP(TRIM(B2),OtherSheet!A:C,3,FALSE))"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
You may also try this:
Code:
ActiveCell.FormulaR1C1 = _
   "=IF(RC[5]=""NO"",NOW(),VLOOKUP(TRIM(RC[-15]),othersheet!C1:C3,3,FALSE))"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thank you PHV and ck1999. The second formula suggestion worked great. Mixing the R1C1 and regular cell references wasn't working. Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top