Delete rows of continuous name if value matches input box

firmament1987

New Member
Joined
Apr 24, 2020
Messages
2
Office Version
  1. 2010
Platform
  1. Windows
i did a for loop if column Purchase item contains "Apple" it will delete it and move on however i want it to also delete all item within customer A not just his "apple" row leaving behind banana row and pear row

so outcome will be only customer C - Papaya and Customer D - pineapple will remain all other rows will be deleted

Please help thanks in advance

NamePurchased item
Customer AApple
Customer ABanana
Customer APear
Customer BApple
Customer CPapaya
Customer DPineapple
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Does this macro do what you want...
VBA Code:
Sub ClearCustomerIfPurchasedApples()
  Dim R As Long, LastRow As Long, ItemToFind As String
  ItemToFind = "apple"
  LastRow = Cells(Rows.Count, "B").End(xlUp).Row
  For R = 2 To LastRow
    If LCase(Cells(R, "B")) = ItemToFind Then
      Range("A2:A" & LastRow) = Evaluate(Replace("IF(A2:A#="""","""",IF(A2:A#=""" & Cells(R, "A").Value & ""","""",A2:A#))", "#", LastRow))
    End If
  Next
  Range("A2:A" & LastRow).SpecialCells(xlBlanks).EntireRow.Delete
End Sub
 
Upvote 0
Hi! Thanks for your help, have been stuck on it for abit it does clear off customer B(which i was able to achieve) but i want it to also clear away all customer A's order so kind of if within customer's order there is an "apple" remove all orders within the same customer's name.

Thanks!
 
Upvote 0
The code I posted did what you are asking for using the sample you posted... I tested it before I posted it. If you are not getting it to work for you, then you will need to post that workbook (obfuscate any sensitive data) to a safe file sharing service (like Drop Box) so we can test our solutions against the actual data that you are working with.
 
Upvote 0
Is the text exactly "Apple"....or are some of them "apple" or "APPLE"
 
Upvote 0

Forum statistics

Threads
1,215,234
Messages
6,123,776
Members
449,123
Latest member
StorageQueen24

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