Offset instead off 2nd vlookup

stapuff

Well-known Member
Joined
Feb 19, 2004
Messages
1,126
I am struggling with this one.

In the following:

in column X I have zip codes for each customer order. For each zip I do 2 vlookup against sheet Lat and Long. The first to find Latitude and 2nd to find longitude.

How can I change the code to get the offset value of the vlookup and not do a 2nd vlookup?

Example -

X3 = 54321 vlookup X3 against sheet "Long & Lat" Column A , return results of column B & C to Y3 and Z3

Column A is list of zip codes
Column B is latitude for zip codes
Column C is longitude for zip codes

Set Rng = Sheets("Lat & Long").Columns("A:C")
With Sheets("Customer Orders")
For Each cell In Range("X3:X" & Range("A1").Value)
On Error Resume Next
If cell.Value > " " Then
.Range("Y" & cell.Row).Value = _
WorksheetFunction.VLookup(cell, Rng, 2, False)
.Range("Z" & cell.Offset(0, 1).Row).Value = _
WorksheetFunction.VLookup(cell, Rng, 3, False)
End If
Next cell
End With


Thanks,

Kurt
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

IML

MrExcel MVP
Joined
Feb 15, 2002
Messages
1,743
I can't really help on the VBA side, but you could determine the row number once with

=MATCH(x3,A1:A10,0)

Store this result and use it in the index function to bring back
=INDEX(X:Y,[match result],1) for X and
=INDEX(X:Y,[match result],2) for Y
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,023
Messages
5,834,999
Members
430,331
Latest member
Syed Yasir Hannan

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top