Deleting a row if number is entered into cell unless another cell contains a number

RayKIII

New Member
Joined
Feb 6, 2014
Messages
37
Excel 2016, Windows 10

I am trying to find a way to delete any data entered into a row if specific text (130 0r 911) in entered into a cell (A4) unless another cell (A1) contains specific text (5). So if the users enter 1 in A1 and then a name in A2 and address in A3 and the 130 in A4 it deletes all data entered into A1, A2, A3, and A4. Now if the users enter a 5 in A1 and 130 0r 911 in A4 then it does nothing and they can continue to enter the data ion the row. I believe this is straight forward but if there are any questions, please let me know.
 

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)
I guess you meant A1, B1, C1 and D1, the cells to check are A1 and D1 of row 1

Put the following code in the events of your sheet

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("D:D")) Is Nothing Then
        If Target.Count > 1 Then Exit Sub
        If Target.Value = "" Then Exit Sub
        If Target.Value = 130 Or Target.Value = 911 Then
            If Cells(Target.Row, "A").Value <> 5 Then
               Range(Cells(Target.Row, "A"), Cells(Target.Row, "D")) = ""
            End If
        End If
    End If
End Sub
 
Last edited:
Upvote 0
Thank you for your response. You are correct, I did mean A1, B1, C1, and D1. Unfortunately, I am still unable to get this to work.
 
Upvote 0
Press Right click on tab sheet, select View Code; In the panel that opens paste code.

Go back to the sheet and capture data
 
Upvote 0
I have and it does not appear to be working.

open

view

https://drive.google.com/file/d/1nGkmNaECp_N8MyaaDbT1M7ByQJ05Vtqy/view?usp=sharing
 
Upvote 0
You put the code in Thisworkbook, in your VBAProject press double click on "Sheet (Sheet1)" in the panel that opens paste the code.

Go back to the sheet and capture data again.
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,310
Members
452,634
Latest member
cpostell

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