Unlock Empty Cells via VBA does not work for merge cells?

actjfc

Active Member
Joined
Jun 28, 2003
Messages
416
Excel Friends,

I found this proven code to Unlock only Empty Cells. I tested in my active sheet that has many vertical and horizontal merged cells. it works for regular cells, but the merged ones are kept unprotected. Can somebody fix it? I appreciate any help. Thanks!

Code:
Sub UnlockEmptyCells()
    
    Application.ScreenUpdating = False
    Cells.Locked = True
    Selection.SpecialCells(xlCellTypeBlanks).Locked = False
    
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
    Application.ScreenUpdating = True

End Sub
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
As a follow up from my prior post, now I am testing this code, and it does not work either, the merged celss <> "" in the used range are not protected :

Code:
Sub LASTTEST()

Dim x As Range

ActiveSheet.Unprotect

For Each x In ActiveSheet.UsedRange
        
        MsgBox x
        
        If x.MergeCells Then
            
        If x = "" Then x.MergeArea.Locked = False Else x.MergeArea.Locked = True
        
        Else
        
        If x = "" Then x.Locked = False Else x.Locked = True
            
        End If

Next

    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
    Application.ScreenUpdating = True


End Sub

Thanks!
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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