Consulting

Results 1 to 5 of 5

Thread: Unlock Blank Cells in Column G

  1. #1
    VBAX Contributor
    Joined
    Apr 2010
    Posts
    182
    Location

    Unlock Blank Cells in Column G

    Hi anyone,

    How could I make the following code to unlock blank cells in column G when a user types a value in cell J10 of the (protected) Active sheet.

    [VBA]Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim Rng
    Dim MyCell
    Set Rng = Range("G18:G53")
    For Each MyCell In Rng
    If MyCell.Value = "" Then

    Else: ActiveSheet.Unprotect
    MyCell.Locked = True
    MyCell.FormulaHidden = False
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
    ActiveSheet.EnableSelection = xlNoRestrictions
    End If
    Next
    End Sub
    [/VBA]

    Any help on this would be kindly appreciated.

    Thanks in advance.
    Best Regards,
    adamsm

  2. #2
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Hi there,

    Not sure I quite follow 100%, but perhaps...

    [vba]Option Explicit

    Private Const TRIGGERRANGE As String = "J10"
    Private Const MYPASSWORD As String = "type your password here"

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim c As Range
    If Target.Address(0, 0) <> TRIGGERRANGE Then Exit Sub
    Me.Unprotect MYPASSWORD
    For Each c In Me.Range("G18:G53")
    If Len(c.Value) = 0 Then
    c.Locked = False
    Else
    c.Locked = True
    c.FormulaHidden = False
    End If
    Next
    Me.Protect MYPASSWORD
    End Sub[/vba]

    HTH

  3. #3
    VBAX Contributor
    Joined
    Apr 2010
    Posts
    182
    Location
    Thanks for the help. The code unlocks all the rows of column G from row G18:G53.

    There are rows which don't contain data in any column within the range. How could I add a line to the code so that it unlocks the cells of column G if the data from Column C to I contains data.

    How could I add a line to the code so that the code only unlocks the rows of column G if the adjacent columns contain data.
    Best Regards,
    adamsm

  4. #4
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Do all of the columns in that row need to contain data? Or just any cell in that row?

  5. #5
    VBAX Contributor
    Joined
    Apr 2010
    Posts
    182
    Location
    Columns C,H,F,I does contain data except G.
    Best Regards,
    adamsm

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •