Using VBA to search for multiple key words in different columns?

Nikki321

New Member
Joined
Oct 4, 2017
Messages
1
Hello I have a large sheet of data and I need to extract key words from a long thread of data to work out the product type with a single key word. The threads look a bit like this:
/Womenswear/Own Buy/Petites WO/Woven Tops
I have done the first step of this by setting up a sheet with key words to search for and then next to it what work I want placed on my data sheet. Example bellow

'Rules sheet'

A B
Footwear Shoes
Bags Bags
Backpack Bags
Wallet Bags
Hat Hats and Caps


Key word in column A on a sheet called ‘rules’ and the word I want column B on the same sheet.
I then have a code to search ‘Sheet1’ column D to check for key word and then put new key work in column AC


Code:
[COLOR="#008000"]Sub ListMarkerD()
    Dim s1 As Worksheet, s2 As Worksheet
    Dim N1 As Long, N2 As Long
    Set s1 = Sheets("Sheet1")
    Set s2 = Sheets("rules")
    N1 = s1.Cells(Rows.Count, "D").End(xlUp).Row    
    N2 = s2.Cells(Rows.Count, "E").End(xlUp).Row
       
    For i = 2 To N1 ''the 1 is starting from cell 1
        v = s1.Cells(i, 4).Value 
        For j = 2 To N2 
            If InStr(1, v, s2.Cells(j, 5).Value) > 0 
                s1.Cells(i, "AC").Value = s2.Cells(j, "F").Value             
End If
        Next j     Next i
End Sub[/COLOR]

[code]


This works fine but now I have some slightly more difficult combinations of key words in different columns in sheet 1 that I need to search by and I am having real problems working out how to do this.

Instead of searching for a single key word and adding the new work in column AC I now need to search for more than one key word in different columns and exclude if there is a third key word.
 For example I need to find everything in column D that has the word Hair and everything in column G that has the words Hair Accessory and put the words Hair Accessories in column, however at the same time I also want to exclude any results that have the word Beauty in column G.

I hope that make sense. Any pointers anyone can give me would be really appreciated.

Thanks
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

Forum statistics

Threads
1,221,469
Messages
6,160,028
Members
451,611
Latest member
PattiButche

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top