Create a Macro that can: Match a value and then save the value and the value from the left while deleting everything else on the spread sheet. The issue is that the values can change position but the value to look for will remain the same. I need to create a macro that can match a value, then save this value and the value to the left while deleting everything else. it may contain two or more different values:

ColumnA ColumnB trees leaves orange fruit tomato vegetable carrot root onion root apple fruit

Then if values are fruit and root should contain:

apple fruit orange fruit carrot root onion root So it more items are added or if they are in different order I can still get the values needed (fruits and roots)

1

There are 1 best solutions below

0
On

I think this what you want. First it asks for the categories to match (defaulting for fruit and root). Then it starts at the bottom of the list and moves up deleting each row that doesn't match.

Sub DeleteUnwantedItems()
    Values = Split(InputBox("Enter space separated categories:", , "fruit root"), " ")
    Row = Range("B1").End(xlDown).Row
    For I = Row To 1 Step -1
        If UBound(Filter(Values, Cells(I, 2).Value)) = -1 Then Rows(I).Delete
    Next
End Sub