Deleting certain cells based on condition in other cell

Jovinchious

New Member
Joined
Oct 12, 2022
Messages
19
Office Version
  1. 2007
Platform
  1. Windows
Hi everyone.
I need one VBA Macro code and just cant go trough it...I ll appreciate any help.
So, I need the following....

If cells in column B start with "1" (i have numbers like 3003, 3200, 11000,10022 etc..) then empty/erase cells of the same row from column "O" to column "Q".

Thanks in advance.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Welcome to the Board!

Try this code:
VBA Code:
Sub MyClearCells()

    Dim r As Long
    Dim lr As Long
    
    Application.ScreenUpdating = False
    
'   Find last row in column B with data
    lr = Cells(Rows.Count, "B").End(xlUp).Row
    
'   Loop through all rows
    For r = 1 To lr
'       See if first character in column B is "1"
        If Left(Cells(r, "B"), 1) = "1" Then
'           Clear column O-Q
            Range(Cells(r, "O"), Cells(r, "Q")).ClearContents
        End If
    Next r
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
Solution
Welcome to the Board!

Try this code:
VBA Code:
Sub MyClearCells()

    Dim r As Long
    Dim lr As Long
   
    Application.ScreenUpdating = False
   
'   Find last row in column B with data
    lr = Cells(Rows.Count, "B").End(xlUp).Row
   
'   Loop through all rows
    For r = 1 To lr
'       See if first character in column B is "1"
        If Left(Cells(r, "B"), 1) = "1" Then
'           Clear column O-Q
            Range(Cells(r, "O"), Cells(r, "Q")).ClearContents
        End If
    Next r
   
    Application.ScreenUpdating = True
   
End Sub
Thank you very much! Works smooth.
 
Upvote 0
You are welcome.
Glad I was able to help!
 
Upvote 0

Forum statistics

Threads
1,224,815
Messages
6,181,136
Members
453,021
Latest member
Justyna P

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