Hello there,
I try to write codes to use keywords in one sheet to search descriptions of products in another sheet, and fill in the categories of the products accordingly. But there is some thing wrong with the codes, and I'm not sure what the problems are.
Please help check my codes below, thanks a lot.
Sub AddCategories()
Dim SearchString As String
Dim Keywords As Variant
Dim rows As Long
' Calculate total rows of data
rows = 2
While ActiveSheet.Cells(rows, 1).Value > 0
rows = rows + 1
Wend
rows = rows - 1
' Search Keywords related row in description
For i = 2 To rows
SearchString = ActiveSheet.Cells(i, 5).Value
Keywords = Workbooks("Category").Worksheets("Category").Range("C2:E9").Value
r = Keywords.Row
A = InStr(1, SearchString, Keywords, vbTextCompare)
'If keywords shows up, then fill in the categories
If (A > 0) Then
'Fill in Categories
ActiveSheet.Cells(i, 3) = Workbooks("Category").Worksheets("Category").Cells(r, 1)
End If
Next
End Sub
I try to write codes to use keywords in one sheet to search descriptions of products in another sheet, and fill in the categories of the products accordingly. But there is some thing wrong with the codes, and I'm not sure what the problems are.
Please help check my codes below, thanks a lot.
Sub AddCategories()
Dim SearchString As String
Dim Keywords As Variant
Dim rows As Long
' Calculate total rows of data
rows = 2
While ActiveSheet.Cells(rows, 1).Value > 0
rows = rows + 1
Wend
rows = rows - 1
' Search Keywords related row in description
For i = 2 To rows
SearchString = ActiveSheet.Cells(i, 5).Value
Keywords = Workbooks("Category").Worksheets("Category").Range("C2:E9").Value
r = Keywords.Row
A = InStr(1, SearchString, Keywords, vbTextCompare)
'If keywords shows up, then fill in the categories
If (A > 0) Then
'Fill in Categories
ActiveSheet.Cells(i, 3) = Workbooks("Category").Worksheets("Category").Cells(r, 1)
End If
Next
End Sub