+ Reply to Thread
Results 1 to 16 of 16

Unhide/ hide rows with password

Hybrid View

megtoma Unhide/ hide rows with... 05-20-2014, 09:37 AM
stnkynts Re: Unhide/ hide rows with... 05-20-2014, 10:31 AM
megtoma Re: Unhide/ hide rows with... 05-20-2014, 11:20 AM
Mowgli2 Re: Unhide/ hide rows with... 05-20-2014, 11:47 AM
megtoma Re: Unhide/ hide rows with... 05-20-2014, 12:01 PM
Excelnoub Re: Unhide/ hide rows with... 05-20-2014, 12:34 PM
Excelnoub Re: Unhide/ hide rows with... 05-20-2014, 12:30 PM
megtoma Re: Unhide/ hide rows with... 05-20-2014, 12:45 PM
Excelnoub Re: Unhide/ hide rows with... 05-20-2014, 12:47 PM
megtoma Re: Unhide/ hide rows with... 05-20-2014, 12:54 PM
Excelnoub Re: Unhide/ hide rows with... 05-20-2014, 01:02 PM
Excelnoub Re: Unhide/ hide rows with... 05-20-2014, 01:05 PM
megtoma Re: Unhide/ hide rows with... 05-20-2014, 03:15 PM
YOUSSEFam Re: Unhide/ hide rows with... 04-28-2023, 03:26 PM
FDibbins Re: Unhide/ hide rows with... 04-29-2023, 12:07 AM
Excelnoub Re: Unhide/ hide rows with... 05-20-2014, 01:00 PM
  1. #1
    Registered User
    Join Date
    04-23-2008
    Posts
    50

    Unhide/ hide rows with password

    Hello,
    Could anyone please help me to create VBA code which keeps rows from 1 to 1000 hidden on a sheet called 'database'. If the user wants to unhide the rows, a password needs to be inputed. There should also be a possibility of hidding the same rows with a password protection again.
    It would be of a great help.

    Thank you.

    Last edited by megtoma; 05-20-2014 at 10:14 AM.

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Unhide/ hide rows with password

    I can't think of an easy way to do it via VBA. Is there a reason you can't use the built in worksheet protection?

  3. #3
    Registered User
    Join Date
    04-23-2008
    Posts
    50

    Re: Unhide/ hide rows with password

    hello,
    One of the sheets in my workbook needs to be viewed by only few people and the excel option to protect the sheet does not really work well when the file is shared... Ony ideas?
    I am really strugling with it...

  4. #4
    Registered User
    Join Date
    03-28-2014
    Location
    N. Ireland
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Unhide/ hide rows with password

    Hii Megtoma,

    VBA can password protect/unprotect sheets and hide/unhide rows for you.

    Would you want a button at the top of the sheet for a user to click and be prompted for a password? If the password is correct it could unlock and unhide the rows. Once they are finished they could click the button to hide the rows again and relock the sheet with the same password. The only "protected" cells would be the 1000 hidden rows so other users could see the rest of the sheet.

    Mowgli

  5. #5
    Registered User
    Join Date
    04-23-2008
    Posts
    50

    Re: Unhide/ hide rows with password

    Hi,
    Yes, this is what I would need. When you mentioned the button... I think it would be better to hide columns from A-E and I would place the button in column G.
    It would be great if you could help.

    Many thanks.

  6. #6
    Forum Contributor
    Join Date
    03-29-2012
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    818

    Re: Unhide/ hide rows with password

    Your Code to hide unhide could be:

    Columns("A:E").EntireColumn.Hidden = True = Not _
    Columns("A:E").EntireColumn.Hidden = True

  7. #7
    Forum Contributor
    Join Date
    03-29-2012
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    818

    Re: Unhide/ hide rows with password

        
    Application.ScreenUpdating = False
        Application.EnableEvents = False
        Password = InputBox("A password is required to run this procedure." & vbCrLf & _
        "Please enter the password:", "Password")
        If Password <> "Your Password here" Then
        MsgBox ("Wrong Password")
        Else
    
    'Your Code Here
        End If
    Application.EnableEvents = True
    Application.ScreenUpdating = True
    Untested

  8. #8
    Registered User
    Join Date
    04-23-2008
    Posts
    50

    Re: Unhide/ hide rows with password

    Many thanks, it works!!! However, is it possible to disable possibility to unhide the columns without using the macro button?

  9. #9
    Forum Contributor
    Join Date
    03-29-2012
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    818

    Re: Unhide/ hide rows with password

    How will the users with the password be able to view the columns that are hidden?

  10. #10
    Registered User
    Join Date
    04-23-2008
    Posts
    50

    Re: Unhide/ hide rows with password

    the code works but the only problem I have is that anyone could come into the sheet and unhide the columns manually by marking the column F, right click and unhide option...

  11. #11
    Forum Contributor
    Join Date
    03-29-2012
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    818

    Re: Unhide/ hide rows with password

    Better to keep the same password for all.
    Change the "hs" to your password... and in bracket pswrd = "Change this to your password" to the same password.

  12. #12
    Forum Contributor
    Join Date
    03-29-2012
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    818

    Re: Unhide/ hide rows with password

    Cleaner and you will only have to change your pswrd on top... (Change "hs" to your password)

    Private Sub CommandButton1_Click()
    Dim pswrd As String
    
    pswrd = "hs"
        Application.ScreenUpdating = False
        Application.EnableEvents = False
        
        Password = InputBox("A password is required to run this procedure." & vbCrLf & _
        "Please enter the password:", "Password")
        
        If Password <> pswrd Then
            MsgBox ("Wrong Password")
        Else
            ActiveSheet.Unprotect pswrd
            Columns("A:E").EntireColumn.Hidden = True = Not _
            Columns("A:E").EntireColumn.Hidden = True
            ActiveSheet.Protect pswrd
        End If
        
        Application.EnableEvents = True
        Application.ScreenUpdating = True
    End Sub

  13. #13
    Registered User
    Join Date
    04-23-2008
    Posts
    50

    Re: Unhide/ hide rows with password

    you are a genius, many thanks

  14. #14
    Registered User
    Join Date
    01-01-2021
    Location
    Morocco
    MS-Off Ver
    2018
    Posts
    31

    Re: Unhide/ hide rows with password

    please how can protect just these specific colums not all sheet, thanks

  15. #15
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,048

    Re: Unhide/ hide rows with password

    Quote Originally Posted by YOUSSEFam View Post
    please how can protect just these specific colums not all sheet, thanks
    Administrative Note:

    Welcome to the forum.

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original.

    Please see Forum Rule #4 about hijacking and start a new thread for your query.

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  16. #16
    Forum Contributor
    Join Date
    03-29-2012
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    818

    Re: Unhide/ hide rows with password

    You could set a password for your sheet then lock it once complete...

    Try this:

    Private Sub CommandButton1_Click()
    Dim pswrd As String
    pswrd = "Change this to your password"
        Application.ScreenUpdating = False
        Application.EnableEvents = False
        Password = InputBox("A password is required to run this procedure." & vbCrLf & _
        "Please enter the password:", "Password")
        If Password <> "hs" Then
               MsgBox ("Wrong Password")
        Else
    ActiveSheet.Unprotect pswrd
    Columns("A:E").EntireColumn.Hidden = True = Not _
    Columns("A:E").EntireColumn.Hidden = True
    ActiveSheet.Protect pswrd
        End If
        Application.EnableEvents = True
        Application.ScreenUpdating = True
    End Sub
    Untested

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] use of password for tab hide/unhide using vba
    By innerise in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-02-2013, 03:36 PM
  2. VBA to Unprotect (w/ password), Unhide, Hide, and Protect (w/ password)
    By pger34 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-14-2012, 12:35 PM
  3. hide / unhide separate sheets based on password
    By spudinsane in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 03-27-2011, 04:48 AM
  4. vba to hide / unhide separate sheets based on password (bis)
    By sigeg in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-26-2011, 05:23 PM
  5. Command button to Hide a tab and unhide a tab with a password
    By nik63 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-08-2011, 07:24 PM

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