Excel UserForm Login and Password for Users in Workbook Table

  • Hello!

    I've been trying to get my login userform to login when clicked based on data in a table in the workbook, but I just can't seem to get the code right.

    Details are:
    Userform username textbox = UsernameTextbox
    Userform password textbox = PasswordTextbox
    Userform submit button = LoginButton

    My workbook has a number of sheets, one of which is "Users". In that sheet, there is a table called "Users_Table". That table has 3 columns: Username [Column A], Password [Column B], Admin (answer is "True" or "False" depending on if they have admin rights) [Column C].

    I'm trying to do this:
    If the username and password is correct for a user AND if the admin column entry is False, then I want to show sheets "Quick Add" and "Overview", I want to make the sheet "Admin" hidden (not VeryHidden since I need to use data on this sheet for other macros), and make "User" sheets VeryHidden so those logged in can't see other users' details. But for users who correctly enter their username and password AND for whom the admin column entry is True, I want to show all sheets. If the username/password combo is incorrect, I want all sheets to be hidden.

    Based on what I've found here, I've been playing with some code and I'm nearly there ( I think!). This is what I'm working with:

    I'm just not sure how I'd go about adding in the Admin requirement mentioned above. I need Admins ("True" in "Admin" column, i.e. Column D, in the "Users_Table") to be able to see all sheets; the code above is just for Users and shows "Quick Add" and "Overview" but hides "Admin" and "Users".

    I also think for the Admins I could Call this macro instead of specifying xlSheetVisible for all sheets, but I haven't got that far yet:

    Sub Unhide_All_Sheets()
    Dim ws As Worksheet
    For Each ws In ActiveWorkbook.Worksheets
    ws.Visible = xlSheetVisible
    Next ws
    End Sub

    I'm fairly new to VBA and I'm trying to teach myself, but I think I'm at an impasse.

    Trying to do this is driving me mad. Any help at all would be much appreciated!

    Thanks for looking and for your time.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!