JumboCactuar
Well-known Member
- Joined
- Nov 16, 2016
- Messages
- 788
- Office Version
- 365
- Platform
- Windows
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Item As String
Dim NItem As String
Dim rFound As Range
Lresult = Len(Target)
'Avoid the endless loop:
Application.EnableEvents = False
Item = Target.Value
If Lresult = 10 Then
With Sheets("Sheet2")
Set rFound = .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
End With
MsgBox (Item)
ElseIf Lresult = 15 Then
NItem = Val(Left(Item, 13))
With Sheets("Sheet2")
Set rFound = .Columns(1).Find(What:=NItem, After:=.Cells(1, 2) _
, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows _
, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
On Error GoTo 0
End With
MsgBox (NItem)
Else
End If
'Enable the Events again:
Application.EnableEvents = True
End Sub
The error occurs at: Find(What:=NItem
I'm guessing due to the left function but can't figure out a solution
Anyone see anything wrong?
Basically wanting to use the first 10 characters in lookup when the Len is 15
Appreciate any help