If A is blank and text in B of same row = "EXAMPLE" ... delete B

Ace71425

Board Regular
Joined
Apr 20, 2015
Messages
130
The title pretty much says it all i'm looking for a VBA code where if a cell in the A column is blank and the subsequent B cell next to it is populated with the string EXAMPLE then delete B. Thanks in advance. Let me know if you need a better example.
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Try:

Code:
Sub Example()
    
    Dim x As Long
    
    For x = 1 To Range("B" & Rows.Count).End(xlUp).Row
        If Range("A" & x) = "" And Range("B" & x) = "Example" Then
            Range("B" & x).ClearContents
        End If
    Next x
    
End Sub
 
Upvote 0
Looks good thanks! It is possible to put this in a worksheet change event so that it happens automatically whereas the macro doesnt need to be ran manually? Like real time if someone tries to put EXAMPLE in b but nothing is in A it deletes right off the bat? Let me know thanks!
 
Upvote 0
Sure. Make sure this is inserted in the sheet code, not in a general module.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    With Target
        If .Column = 2 And .Value = "Example" And .Offset(, -1) = "" Then
            .ClearContents
        End If
    End With
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,954
Messages
6,122,462
Members
449,085
Latest member
ExcelError

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