Clear data based on cell

bobaol

Board Regular
Joined
Jun 3, 2002
Messages
225
Office Version
  1. 365
  2. 2003 or older
Platform
  1. Windows
Hello, i have a few thousand cells in column AA containing the word BlankClearMe. I want to clear A to BZ when the word is found. For example, cell AA14=BlankClearMe, then clear A14 to BZ14. or when AA2397=BlankClearMe, then clear A2397 to BZ2397. any help is appreciated. Thanks in advance.
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Try this:
VBA Code:
Sub MyClearCells()

    Dim lr As Long
    Dim r As Long
   
    Application.ScreenUpdating = False
   
'   Find last row in column AA with data
    lr = Cells(Rows.Count, "AA").End(xlUp).Row
   
'   Loop through all rows starting from row 1
    For r = 1 to lr
'       Check to see if value in column AA is "BlankClearMe"
        If Cells(r, "AA") = "BlankClearMe" Then
'           Clear cells
            Range(Cells(r, "A"), Cells(r, "BZ")).ClearContents
        End If
    Next r
   
    Application.ScreenUpdating = True
   
    Exit Sub
   
End Sub
 
Upvote 0
Solution
Just another option to test if using 2010 or newer

VBA Code:
Sub FilterClear()
    Application.ScreenUpdating = False
   
    With Range("AA1:AA" & Range("AA" & Rows.Count).End(xlUp).Row)
   
        .AutoFilter 1, "BlankClearMe"
       
        On Error Resume Next
       .Offset(1, -26).Resize(.Rows.Count - 1, 78).SpecialCells(xlCellTypeVisible).ClearContents
        On Error GoTo 0
        ActiveSheet.ShowAllData
   
    End With
   
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Thank you both Joe4 and Mark858. Both worked well. - bobaol44484
 
Upvote 0
You are welcome.
Glad we were able to help!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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