i have a code when on cell change then loop and fine matching value. then offset and paste in cell to left.
code works fine but need it to work faster. Any help would be appreciated.
code works fine but need it to work faster. Any help would be appreciated.
VBA Code:
Sub Worksheet_Change(ByVal Target As Range)
Dim KeyCells As Range
Set KeyCells = Sheet1.Range("C2:C50")
If Not Application.Intersect(KeyCells, Range(Target.Address)) _
Is Nothing Then
Dim i As Long
Dim j As Long
Dim lastrow As Long
Dim ws As Worksheet, ws2 As Worksheet
Set ws = Sheet1
Set ws2 = Sheet2
For i = 2 To 5000
If IsEmpty(ws.Range("C" & i)) Then
Exit For
End If
For j = 2 To 5000
If IsEmpty(ws2.Range("E" & j)) Then
Exit For
End If
If ws.Range("C" & i).Text = ws2.Range("E" & j).Text Then
If ws.Range("B" & i).Value = "" Then
ws.Range("B" & i).Value = ws2.Range("E" & j).Value & "-" & ws2.Range("B" & j).Value
Exit For
End If
End If
Next j
Next i
End If
End Sub