Consulting

Results 1 to 8 of 8

Thread: Problem with sheet protection

  1. #1

    Exclamation Problem with sheet protection

    Hi,

    I want to make certain cells non-editable in the sheet. I am using the following code:

    DestinationSheet.Cells.Locked = False
    DestinationSheet.Range("N13:N52").Locked = True
    DestinationSheet.Protect

    But this is making the sheet protected and I cannot do further operations on the sheet. Is there a workaround?

    Thanks for your help.

  2. #2
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,121
    Location
    Try adding the following line[VBA]ActiveSheet.EnableSelection = xlUnlockedCells[/VBA]
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  3. #3

    Need help

    This is not solving the problem.

    Can someone please help.

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,445
    Location
    What other operations can you not do?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5

    Exclamation other operations

    Hi,

    I have a macro defined on the sheet that pulls up some data from MS SQL Server and displays it on the sheet. That macro is not running.

    That macro runs if I physically Unprotect the sheet by choosing a menu option.

    If I unprotect the sheet before running the macro then the cells are no longer locked.

    Please help.

  6. #6
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,121
    Location
    Then may I suggest that you post your code so we can see. Else follow the logic of this layout
    [VBA]
    Sub RunMacro()

    Sheet1.Unprotect Password:="Secret" ‘ß=== Change sheet name to suit

    'Your Macro Code

    Sheet1.Protect Password:="Secret" ‘ç=== Change sheet name to suit

    End Sub
    [/VBA]
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  7. #7

    Code

    Here's my code:

    [VBA] Range("B3").Select
    ActiveCell.FormulaR1C1 = "9"
    Cells.Select
    Selection.Locked = False
    Selection.FormulaHidden = False
    Range("B3").Select
    Selection.Locked = True
    Selection.FormulaHidden = False
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, [VBA][/VBA] Scenarios:=True
    ActiveSheet.EnableSelection = xlUnlockedCells[/VBA]
    Last edited by Bob Phillips; 08-26-2011 at 01:32 AM. Reason: Added VBA tags

  8. #8
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,445
    Location
    [vba]

    Range("B3").Value = 9
    With Cells
    .Locked = True
    .FormulaHidden = True
    End With
    With Range("B3")
    .Locked = False
    .FormulaHidden = False
    End With
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
    ActiveSheet.EnableSelection = xlUnlockedCells
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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