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

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
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,223,888
Messages
6,175,213
Members
452,618
Latest member
Tam84

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