Plz help: need vba to force user can't delete cell if another cell has value

love_guy_1977

Board Regular
Joined
Aug 5, 2006
Messages
111
Hi,

I'm having data in column A, B and C.
B1 can't be filled if A1 is empty & C1 can't be filled if B1 is empty. And so on for each row. I mean C2, C3, C4 till C20

So how can I force user not to delete B1 if C1 is filled as well as not to delete A1 if B1 or/and C1 are filled. And the same will be for A2 , B2 & for A3 , B3 and so on till A20 , B3


Thank you
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
If can't do it all in one go. I need at least someone write a vba that can't delete cell if another cell has value.

Then i will try to make for all
 
Upvote 0
Hi guys,

here you go but it is for one row

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Application.Intersect(Target, [A1]) Is Nothing Then
        If [A1] = "" Then
        If [B1] <> "" Or [C1] <> "" Then
        Application.EnableEvents = False
        Application.Undo
        Application.EnableEvents = True
        End If
        End If
    End If
End Sub

So i need someone do something like this


For each oCell in range("A1:A20")
Target = oCell
.
.
.
.
.


Thank you
 
Last edited:
Upvote 0
I got it
and it is here for any body need it

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim oCell As Range
For Each oCell In Target
    If Not Intersect(oCell, Range("D11:D46")) Is Nothing Then
        If oCell = "" Then
            If oCell.Offset(0, 3) <> "" Or oCell.Offset(0, 5) <> "" Or oCell.Offset(0, 6) <> "" _
            Or oCell.Offset(0, 8) <> "" Or oCell.Offset(0, 9) <> "" Or oCell.Offset(0, 10) <> "" Then
                Application.EnableEvents = False
                Application.Undo
                Application.EnableEvents = True
            End If
        End If
    End If
Next oCell
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,537
Messages
6,179,405
Members
452,911
Latest member
a_barila

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