We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

VBA VLOOKUP

Seamus2626
Seamus2626 asked
on
Medium Priority
532 Views
Last Modified: 2012-05-11
Hi,

I have two VBA Editor Vlookups (attached)

In excel, the first lookup returns formulae:
=VLOOKUP(L2,'[Prime Dividends Checker.xls]PAID DIVS'!$D:$D,1,0)

The second returns:
=VLOOKUP(W2,'[Prime Dividends Checker.xls]PAID DIVS'!'E4',1,0)

The key difference in the returned formulae is the second does not search the column

I recorded the forst vlookup as a macro and then copy/pasted it for the second, adjusting columns


Why is there is a diffirence in result when the first formulae is the same in the editor?

Thanks
Seamus


.Range("AC2").Formula = "=VLOOKUP(RC[-17],'[Prime Dividends Checker.xls]PAID DIVS'!C4,1,0)"
    .Range("AD2").Formula = "=VLOOKUP(RC[-7],'[Prime Dividends Checker.xls]PAID DIVS'!E4,1,0)"

Open in new window

Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2011
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Rob HensonFinance Analyst
CERTIFIED EXPERT
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
CERTIFIED EXPERT
Most Valuable Expert 2011
Awarded 2010

Commented:
Hello,
in this formula

=VLOOKUP(L2,'[Prime Dividends Checker.xls]PAID DIVS'!$D:$D,1,0)

the lookup range is the whole column D

In the second formula,

=VLOOKUP(W2,'[Prime Dividends Checker.xls]PAID DIVS'!'E4',1,0)

the lookup range consists of just one cell, E4. So unless the search term is present in that cell, the Vlookup will return an error.

The second formula in your code snippet also refers to just one cell as the lookup range. That won't work well. You need a range with more than one row for a meaningful result.

cheers, teylyn

Author

Commented:
Thanks Fellas,

Understand now.

Cheers,
Seamus

Author

Commented:
Thank you too Teylyn, just seen your response

Thanks
Seamus
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.