• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How to use keywords to search in the descriptions?

poren123

New Member
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
 
Back
Top