Unlock Blank cells

adamsm

Active Member
Joined
Apr 20, 2010
Messages
444
Hi anyone,

How could I write a standard module code that would unlock all the blank cells in column G on a protected sheet without a password?

My range is from G18:G50.

Any help on this would be kindly appreciated.

Thanks in advance.
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Try like this

Code:
Sub UnLockG()
ActiveSheet.Unprotect Password:="Adam"
Range("G18:G50").SpecialCells(xlCellTypeBlanks).Locked = False
ActiveSheet.Protect Password:="Adam"
End Sub
 
Upvote 0
Thanks for the help. Suppose the adjacent columns C is empty. How could I make the code not to unlock those rows if column G when the present code unlocks the empty cells in column G.

Meaning even if the cells of column G is empty but the columns C does not contain anything, the code would not unlock that row of column G.

Any help on this would be kindly appreciated.
 
Upvote 0
Try

Code:
Sub UnLockG()
Dim c As Range
ActiveSheet.Unprotect Password:="Adam"
For Each c In Range("G18:G50").SpecialCells(xlCellTypeBlanks)
    If c.Offset(, -4).Value <> "" Then
        c.Locked = False
    Else
        c.Locked = True
    End If
End If
ActiveSheet.Protect Password:="Adam"
End Sub
 
Upvote 0
Oops!

Rich (BB code):
Sub UnLockG()
Dim c As Range
ActiveSheet.Unprotect Password:="Adam"
For Each c In Range("G18:G50").SpecialCells(xlCellTypeBlanks)
    If c.Offset(, -4).Value <> "" Then
        c.Locked = False
    Else
        c.Locked = True
    End If
Next c
ActiveSheet.Protect Password:="Adam"
End Sub
 
Upvote 0
There is a non-looping solution available to this question...
Code:
Sub UnLockG()
  Dim Blanks As String
  ActiveSheet.Unprotect Password:="Adam"
  With Range("G18:G50").SpecialCells(xlCellTypeBlanks)
    .Locked = False
    Intersect(.Cells, .Offset(, -4).SpecialCells(xlCellTypeBlanks).EntireRow).Locked = True
  End With
  ActiveSheet.Protect Password:="Adam"
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,584
Messages
6,179,687
Members
452,938
Latest member
babeneker

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