Prevent cells being deleted using VBA

Milos

Board Regular
Joined
Aug 28, 2016
Messages
121
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I am in need of a VBA macro to stop a section of cells (F28:J36) from being deleted from a specific worksheet as they have important formulas in them. But I need the cells to be editable. I currently have simultaneous code which automatically hides the rows based on certain conditions which is why I cannot use the sheet protection method of preventing cells from being deleted (as I had encountered too many errors with this) and being hidden the cells contents are getting deleted too often!

Current code:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Rows("28:36").Hidden = LCase(Range("B5").Value) = 1
  Rows("45:52").Hidden = LCase(Range("B5").Value) = 1
  Rows("58:59").Hidden = LCase(Range("B6").Value) = "no"
End Sub

Any help with my problem would be greatly appreciated.

Cheers,

Milos
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Maybe set an AutoFilter with the Sheet's Protect option to "Use AutoFilter"? Obviously, cells you don't want deleted would be locked.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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