I have used the exact same code below for different sheets and it works correctly, but when I edited it for a new set of sheets in the same workbook the Run Time error comes up.
Private Sub cmdSearchKitDesc_Click()
Dim RowNum As Long
Dim SearchRow As Long
RowNum = 3
SearchRow = 3
Worksheets("Kit_database").Activate
Do Until Cells(RowNum, 1).Value = ""
If InStr(1, Cells(RowNum, 3).Value, txtKitKeyword.Value, vbTextCompare) > 0 Then
Worksheets("Kit_search").Cells(SearchRow, 2).Value = Cells(RowNum, 2).Value
Worksheets("Kit_search").Cells(SearchRow, 3).Value = Cells(RowNum, 3).Value
Worksheets("Kit_search").Cells(SearchRow, 4).Value = Cells(RowNum, 4).Value
Worksheets("Kit_search").Cells(SearchRow, 5).Value = Cells(RowNum, 6).Value
Worksheets("Kit_search").Cells(SearchRow, 6).Value = Cells(RowNum, 8).Value
Worksheets("Kit_search").Cells(SearchRow, 7).Value = Cells(RowNum, 9).Value
SearchRow = SearchRow + 1
End If
RowNum = RowNum + 1
Loop
If SearchRow = 2 Then
MsgBox "No kits were found that match your criteria."
Exit Sub
End If
lstKitResult.RowSource = "KitKit"
End Sub
I have changed RowNum to 3 to match the column of the sheet (in this case I would like to search the description of a kit) I would like to search and respectively in the string. I have carefully checked that the sheets and OFFSET function that it uses are named correctly.
The list box I would like to populate uses,
lstKitResult.RowSource = "KitKit"
where "KitKit" uses the following OFFSET formula,
=OFFSET(Kit_search!$B$3,0,0,COUNTA(Kit_search!$C:$C)-1,6)
The "Kit_database" sheet holds all the different types of kits I would search from. The "Kit_search" sheet is a placeholder for all the results found that match the kit description searched. The OFFSET function pulls data "Kit_search" that should be populated with the search results of txtKitKeyword.Value
I have tried different column numbers and sheet names to make sure that things match up but the Run Time error always comes up.