Consulting

Results 1 to 3 of 3

Thread: Locking blank cells only via VBA

  1. #1
    VBAX Contributor
    Joined
    Aug 2007
    Posts
    165
    Location

    Locking blank cells only via VBA

    Public Sub Lock_Blanks()
    Dim objCell As Range

    ActiveSheet.Unprotect ""

    On Error Resume Next
    ActiveSheet.UsedRange.SpecialCells(xlCellTypeConstants).Locked = True
    ActiveSheet.UsedRange.SpecialCells(xlCellTypeFormulas).Locked = True
    On Error GoTo 0

    ActiveSheet.Protect ""
    End Sub

    Hi experts

    i cannot amend the above to lock blank cells only any pointer for the non VBa person.

    thanks

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Why not lock eveything first, then unlock?
    [VBA]
    ActiveSheet.Cells.Locked = True
    ActiveSheet.UsedRange.SpecialCells(xlCellTypeConstants).Locked = False
    ActiveSheet.UsedRange.SpecialCells(xlCellTypeFormulas).Locked = False

    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Contributor
    Joined
    Aug 2007
    Posts
    165
    Location
    thanks for the feed back

Posting Permissions

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