How can I run this code on a locked cell?

boznian

Board Regular
Joined
Mar 25, 2003
Messages
167
I am using the following code to apply the *result* of a formula in place of the actual formula in the same cell:

Code:
    Cells(crow, "AQ:AQ").Activate
    Selection.Copy
    Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
       False, Transpose:=False
    Application.CutCopyMode = False

This works fine as long as the cells are unlocked but I really need to keep them locked - can this be done?
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
you need to Unprotect your sheet then Protect

Code:
ActiveSheet.Unprotect "YourPassword"
Your code
ActiveSheet.Protect "YourPassword"

HTH
 
Upvote 0
Code:
 Cells(crow, "AQ:AQ").Activate
 Selection.Locked = False
 Selection.Copy  Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _        False, Transpose:=False  
 Application.CutCopyMode = False
 Selection.Locked = True
 
Upvote 0
Thanks guys-

I like the
Selection.Locked = False
solution better but it won't work for me - maybe because I am on Excel 2003? So using the
ActiveSheet.Unprotect
statements is doing the job.

Thanks!!
 
Upvote 0
Follow-up-

I didn't immediately realize that this

Code:
ActiveSheet.UnProtect 
formulas and code here...
ActiveSheet.Protect

was resetting all my protection options, which meant I could no longer filter the sheet or format cells. So code was changed to this:

Code:
ActiveSheet.UnProtect
formulas and code here...
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
        , AllowFormattingCells:=True, AllowFiltering:=True
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

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