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.
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.