VBA - Check value on range and delete its line

vabtroni

New Member
Joined
Aug 1, 2017
Messages
43
Office Version
  1. 365
Platform
  1. Windows
Hello everyone, hope I can find you all ok.

Now to question. The range is A1:B20. I need a macro that checks the values on column B within that range, and whenever the value there is 0, "" or has letters, it deletes the cell content on both column B and A.

Any chance I could get some help here?

Best regards everyone,
Vasco.
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Can you post a sample of your data, so we can see what it looks like and what it is that you are trying to leave?
Are you just trying to leave non-zero numeric values?
 
Upvote 0
Can you post a sample of your data, so we can see what it looks like and what it is that you are trying to leave?
Are you just trying to leave non-zero numeric values?
Yes. The value on column B must be non-zero numeric values. All other data on column B will force the macro to delete it, as well as the value on the same line on column A. :-)
 
Upvote 0
Try this code:
VBA Code:
Sub MyClearMacro()

    Dim r As Long
    
    Application.ScreenUpdating = False
    
    For r = 1 To 20
'       Check to see if value in column B is numeric
        If IsNumeric(Cells(r, "B")) And Cells(r, "B") <> 0 Then
'           Do nothing
        Else
'           Clear columns A and B
            Range(Cells(r, "A"), Cells(r, "B")).ClearContents
        End If
    Next r
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,157
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