I have some problems defining that check. It’s only a part of whole code with Do Untilloop.
If any row in my sheet matches searched value define FindRow as "1".
If matching row is found then FindRow = that row number.
With ThisWorkbook.Sheets("TKSLIST").Range("A:A")
FindRow = 1
strTKSname = ws.Cells(i + 1, 11).Text
If .Find(What:=strTKSname, LookAt:=xlPart, LookIn:=xlValues, MatchCase:=False).Row Is Nothing Then
FindRow = 1
Else
FindRow = .Find(What:=strTKSname, LookAt:=xlPart, LookIn:=xlValues, MatchCase:=False).Row
End If
End With
I’m missing there something. Everytime when my searched value is not found I’m getting errors.
>Solution :
-
Declare your variables properly
-
Get the range wher something was found as
FoundAtand compare that againstNothing -
Remove else part because
FindRow = 1was already set as initial value.
With ThisWorkbook.Sheets("TKSLIST").Range("A:A")
Dim FindRow As Long
FindRow = 1
Dim strTKSname As String
strTKSname = ws.Cells(i + 1, 11).Text
Dim FoundAt As Range
Set FoundAt = .Find(What:=strTKSname, LookAt:=xlPart, LookIn:=xlValues, MatchCase:=False)
If Not FoundAt Is Nothing Then
FindRow = FoundAt.Row
End If 'no else needed because initialized as `FindRow = 1`
End With