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

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
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,224,823
Messages
6,181,185
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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