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

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
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,224,820
Messages
6,181,154
Members
453,021
Latest member
Justyna P

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