+ Reply to Thread
Results 1 to 3 of 3

Excel 2007 : VBA - Password Protect Sheet / certain cells

  1. #1
    Registered User
    Join Date
    11-17-2011
    Location
    Shropshire
    MS-Off Ver
    Excel version 2102
    Posts
    85

    VBA - Password Protect Sheet / certain cells

    Hi.

    I have a spreadsheet, it basically contains a list of dates from October 2011 to March 2012 - I am trying to create a button so when hit say the rows for October hide, and when hit again rows for October appear. I am also trying to protect most of the cells but a range of cells to be unlocked for editing.

    I have managed to do the above, however if I am passing this spreadsheet on to a colleague, they can unlock the cells - how do I put a password on to protect the cells.

    Any advise would help. thanks.

    The VBA code i have so far is:

    Private Sub December_Click()
    If December.Value = True Then

    Worksheets("Timesheet").Unprotect
    'This area contains the things you want to happen
    'when the toggle button is not depressed
    Rows("120:171").EntireRow.Hidden = False
    Worksheets("Timesheet").Rows("120:129").Locked = True
    Worksheets("Timesheet").Range("A130:C171,L130:Z171,D116:K171").Locked = True
    Worksheets("Timesheet").Protect


    Else

    Worksheets("Timesheet").Unprotect
    'This area contains the things you want to happen
    'when the toggle button is depressed
    Rows("120:171").EntireRow.Hidden = True
    Worksheets("Timesheet").Rows("120:129").Locked = True
    Worksheets("Timesheet").Protect


    End If
    End Sub

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: VBA - Password Protect Sheet / certain cells

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    11-17-2011
    Location
    Shropshire
    MS-Off Ver
    Excel version 2102
    Posts
    85

    Re: VBA - Password Protect Sheet / certain cells

    Hi.

    I have a spreadsheet, it basically contains a list of dates from October 2011 to March 2012 - I am trying to create a button so when hit say the rows for October hide, and when hit again rows for October appear. I am also trying to protect most of the cells but a range of cells to be unlocked for editing.

    I have managed to do the above, however if I am passing this spreadsheet on to a colleague, they can unlock the cells - how do I put a password on to protect the cells.

    Any advise would help. thanks.

    The VBA code i have so far is:

    Please Login or Register  to view this content.
    (Sorry Roy, Didn't mean to break rules, hope i've done it correct this time!)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1