Consulting

Results 1 to 4 of 4

Thread: Protect only selected cells

  1. #1
    VBAX Contributor
    Joined
    May 2008
    Posts
    109
    Location

    Protect only selected cells

    Good Morning,
    I need to protect only some cells of a column, for example column H, from H16 to H 139 by a macro. Is there a little help.

    Thanks

  2. #2
    VBAX Contributor
    Joined
    Feb 2009
    Posts
    103
    Location
    hi sasa, try this:

    to unlock go to tools-> Protection->Unprotect sheet

    [vba]
    Sub x()

    '
    ' Macro4 Macro
    ' Macro recorded 3/28/2009 by joms
    '

    '
    Cells.Select
    Selection.Locked = False
    Selection.FormulaHidden = False
    Range("h16:h139").Select
    Selection.Locked = True
    Selection.FormulaHidden = False
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True

    End Sub

    [/vba]
    Last edited by joms; 03-28-2009 at 04:53 AM.

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Tidying up Joms' code to get rid of these inefficient selections
    [VBA]
    Sub x()
    With Cells
    .Locked = False
    .FormulaHidden = False
    With .Range("h16:h139")
    .Locked = True
    .FormulaHidden = False
    End With
    End With
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
    End Sub

    [/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'

  4. #4
    VBAX Contributor
    Joined
    Feb 2009
    Posts
    103
    Location
    thanks, mdmackillop... that code was just recorded... at i least i learn something from you...

Posting Permissions

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