Vlookup code....

ExcelNovice

Well-known Member
Joined
May 12, 2002
Messages
583
Hi all,

I'm trying to tweak the following code so that when I enter data in cells A2:A1000, Vlookup will search the data on sheet 2 and if the value is found, shows the corresponding data on sheet 1 in cells B2:11000. The macro works fine now, but it only allows me to enter data in cell A2 only and then it searches the data on sheet 2, and if the value is found it shows it on sheet 1 in cells B2:i2.

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, [A2]) Is Nothing Then
Application.EnableEvents = False
Application.ScreenUpdating = False
Dim LastUsed As Long
LastUsed = Cells(Rows.Count, 2).End(xlUp).Row
Range("B1:I" & LastUsed).Clear
With Sheet2
.Columns("A:I").AutoFilter Field:=1, Criteria1:=Target.Value
.[B:I].Copy [B1]
.Cells.AutoFilter
End With
End If
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub

Thanks for your help.
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
In B2 (and copy down)

=VLOOKUP(A2,'Sheet2'!$A$1:$B$1000,2,0)

Assumptions:
• Your lookup table is in the range 'Sheet2'!$A$1:$B$1000
• The value being looked up (A2) will be in column A of the lookup table
• The value being returned from the lookup table is in the second column (column B).

Just make the necessary changes to the formula to accomodate your data.

Regards,
 
Upvote 0
Thanks Barrie.
How do I change this so the value being returned is from the second, third and fourth columns on the lookup table (B, C, D & E)?
 
Upvote 0
ExcelNovice said:
Thanks Barrie.
How do I change this so the value being returned is from the second, third and fourth columns on the lookup table (B, C, D & E)?

Change the second last variable (and your data range of course). So to return a value from column C
=VLOOKUP(A2,'Sheet2'!$A$1:$C$1000,3,0)
column D
=VLOOKUP(A2,'Sheet2'!$A$1:$D$1000,4,0)
etc.
 
Upvote 0

Forum statistics

Threads
1,214,621
Messages
6,120,568
Members
448,972
Latest member
Shantanu2024

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
Back
Top