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

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
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,221,417
Messages
6,159,789
Members
451,589
Latest member
Harold14

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