Speeding up VBA Vlookup on Worksheet Change

JumboCactuar

Well-known Member
Joined
Nov 16, 2016
Messages
788
Office Version
  1. 365
Platform
  1. Windows
Hi,
i have the following which on worksheet change, looks up the value in column A and outputs the matching data from Data Sheet

it uses the FIND vba function but im unsure if theres a better way to do this as it can lag on fast input:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)


Dim Item As String
Dim Item_Found As Range


If Left(Target.Address, 3) = "$A$" Then
    If Target.Cells.Count > 1 Then Exit Sub
    If Target.Row < 2 Then Exit Sub
    If Target = "" Then Exit Sub


'Avoid the endless loop:
Application.EnableEvents = False


Item = Target.Value


'Lookup - OrderID
    With Sheets("Data")
        Set Item_Found = .Columns(1).Find(What:=Item, After:=.Cells(1, 1) _
                , LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows _
                , SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
    
        On Error GoTo 0
    
            If Not Item_Found Is Nothing Then
                Target.Offset(0, 1).Value = Item_Found.Offset(0, 1).Value
                Target.Offset(0, 2).Value = Item_Found.Offset(0, 7).Value
                Target.Offset(0, 3).Value = Item_Found.Offset(0, 8).Value
                Target.Offset(0, 4).Value = Item_Found.Offset(0, 9).Value
                Target.Offset(0, 5).Value = Item_Found.Offset(0, 10).Value
                Target.Offset(0, 6).Value = Item_Found.Offset(0, 11).Value
                Target.Offset(0, 7).Value = Item_Found.Offset(0, 12).Value
                Target.Offset(0, 8).Value = Item_Found.Offset(0, 13).Value
            Else
              
            End If
    End With
   
End If


'Enable the Events again:
Application.EnableEvents = True




End Sub

any recommended changes ?
 
Last edited:

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Why not replace the macro with an index/match formula?
 
Upvote 0
Why not replace the macro with an index/match formula?

The resulting data is editable and then i use the same method to update the record in data sheet so the formulas would be overwritten.
 
Upvote 0
Ok, probably no quicker, but you could use
Code:
Private Sub Worksheet_Change(ByVal Target As Range)


Dim Item As String
Dim Item_Found As Range


If Left(Target.Address, 3) = "$A$" Then
    If Target.Cells.Count > 1 Then Exit Sub
    If Target.Row < 2 Then Exit Sub
    If Target = "" Then Exit Sub


'Avoid the endless loop:
Application.EnableEvents = False


Item = Target.Value


'Lookup - OrderID
    With Sheets("pcode")
        Set Item_Found = .Columns(1).Find(What:=Item, After:=.Cells(1, 1) _
                , LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows _
                , SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
    
    
            If Not Item_Found Is Nothing Then
                Target.Offset(0, 1).Value = Item_Found.Offset(0, 1).Value
                Target.Offset(0, 2).Resize(, 7).Value = Item_Found.Offset(0, 7).Resize(, 7).Value
            End If
    End With
   
End If


'Enable the Events again:
Application.EnableEvents = True




End Sub
 
Upvote 0
thanks i will try this

i added disable screenupdating also that seems to speed it up
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,271
Members
452,628
Latest member
dd2

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