Clearing data for locked cells or protected worksheet

hobbes11

New Member
Joined
Oct 8, 2017
Messages
18
I need to clear the below data except formula in sheet(invoice) after I copy data into sheet(report). The sheet (invoice) will be protected by locking some of the cells for any editing. If i protect the worsheet there is no way my macro can run.

In Column B7 - manual data input
Column B9 - drop down list
Colum B10:B13 - Vlookup

In Column F10 - today () formula
Column F11 & F12 - drop down list
Column F14 - manual data input

In column A18:A41 - drop down list
column B18:B41 - Vlookup formula
column C18:C41 & D18:D41 - drop down list
column E & F - manual data input
column F49 - drop down list

In Row 44:48 - manual data input

My current code:

Private Sub CmdClearData_Click()
'Remove data but not formulaAns = MsgBox("Have you update to report?", vbYesNo + vbQuestion)
If Ans = vbNo Then Exit Sub
Sheet1.Range("B7:B13").SpecialCells(xlCellTypeConstants).ClearContents
Sheet1.Range("F11:F15").SpecialCells(xlCellTypeConstants).ClearContents
Sheet1.Range("A19:F41").SpecialCells(xlCellTypeConstants).ClearContents
Sheet1.Range("A44:F48").SpecialCells(xlCellTypeConstants).ClearContents
End Sub
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
You can get your macro to run by having it unprotect the sheet at the beginning and then protecting it again at the end. For example:
Code:
Activesheet.Unprotect
'Your code here
Activesheet.Protect
 
Upvote 0
your code works fine but when i run the macro, all my data in cells which I have locked are also deleted. ??
 
Upvote 0
Unprotecting and protecting your sheet shouldn't make any difference in how the rest of the macro works. If it was working properly before, it should work properly after unprotecting and protecting the sheet. The only ranges that should be cleared are the ones you mentioned in your original post. Was your macro working properly when the sheet was originally unprotected?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
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