How to un-protect multiple cells in Excel worksheet with VBA

BizBoy

Board Regular
Joined
Jul 26, 2012
Messages
118
Hi,

How to un-protect multiple cells in Excel worksheet with coding.
I have a worksheet.
I need to protect entire worksheet apart from few cells.

I tried various solutions from Google but somehow it is not working for me.
For example, I want to keep cell A1, B5, C10, D15, E20 unprotected.
And rest of the worksheet should be protected.

How do I do this
Can anyone please help me in this.

I tried various options for below code but not successful.

Code:
Sub Protect_My_Range()
    Dim TempBook As Workbook
    Dim TempSht As Worksheet
    
    Dim TempRng As Range
    Dim TRange As Range
    
    Set TempBook = ActiveWorkbook
    Set TempSht = TempBook.ActiveSheet
    
    TempSht.Range("F7").Locked = False
    TempSht.Range("N7").Locked = False
    
TempSht.Protect "temp"
End Sub
 
Last edited:
Do any of the cells you are unlocking intersect with a merged cell?
 
Upvote 0

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Hi Fluff sir, sorry for late reply.
Yes, most of these cells are merged.
And I am not able to understand how to un-protect these cells.
 
Upvote 0
You need to specify the full address of the merged cells, so instead of using K7, it would need to be something like K7:M7
 
Upvote 0

Forum statistics

Threads
1,214,929
Messages
6,122,315
Members
449,081
Latest member
tanurai

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