Prevent column/ row from deleting

xzaqus

New Member
Joined
Sep 24, 2017
Messages
33
Using VBA code,

1. Is it possible to block deleting, say Row 10 and Column P (but the other rows and columns should be deletable)?

2. If a sheet contains a value 'Do not delete", then the row and column of the cell should not be deletable? That is, the code should pick up the column address and row address wherever there is "Do not delete" in the sheet and then those rows and columns should be prevented from being deleted.

Thanks.
 
Last edited:

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Sort of figured out 1 with

Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("P10")) Is Nothing Then Exit Sub
On Error GoTo ExitPoint
Application.EnableEvents = False
If Not IsDate(Target(1)) Then
Application.Undo
MsgBox " You can't delete cell contents from this range ", vbCritical, ""
End If
ExitPoint:
Application.EnableEvents = True
End Sub
 
Upvote 0
This code below, finds the address of Do not delete cell (currently displaying as a message). I am not able to pass r.address to the worksheet_change sub posted above instead of p10. That is, the above code should prevent deleting the cells/column/ row containing do not delete found using the code below. Any help will be appreciated.

Sub WhereIs()
Dim r As Range
For Each r In ActiveSheet.UsedRange
If InStr(1, r.Text, "Do not delete") > 0 Then
MsgBox = r.Address
Exit Sub
End If
Next r
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,323
Members
452,635
Latest member
laura12345

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