I'm trying to get my VBA code to do a vlookup match in a table with 3 columns and when it finds a match it should copy the right sheets to another file.
I have a userform which a username has to be entered in. Then it matches this username (column A) to a cell with sheetnames in (column C). How can I define this vlookup to match and then copy the multiple sheets. And how should I format the sheetnames in column C?
My table looks like this right now: A: User (for example "Alexandra") B: Password (for example "Test 1") C: Sheets (for example "Sheet 1, Sheet 2")
Thanks!
EDIT:
My current code for the password authorization, this is based on a Userform:
Private Sub cmdLogin_Click()
Dim RowNo As Long
Dim Id As String, pw As String
Dim ws As Worksheet
Dim aCell As Range
On Error GoTo ErrorHandler
If Len(Trim(txtLogin)) = 0 Then
txtLogin.SetFocus
MsgBox "Gebruikersnaam moet ingevuld zijn."
Exit Sub
End If
If Len(Trim(txtPassword)) = 0 Then
txtPassword.SetFocus
MsgBox "Wachtwoord moet ingevuld zijn."
Exit Sub
End If
Application.ScreenUpdating = False
Set ws = Worksheets("PW")
Id = LCase(Me.txtLogin)
Set aCell = ws.Columns(1).Find(What:=Id, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
'~~> If match found
If Not aCell Is Nothing Then
RowNo = aCell.Row
'~~> Rest of your code. For example if the password is
'~~> Stored in Col B then
'~~> Replace txtPassword with the actual name of password textbox
If Me.txtPassword = aCell.Offset(, 1) Then
Call CopySheets()
Unload Me
Else
MsgBox "De ingevoerde gegevens zijn onjuist. Probeer het opnieuw.", vbOKOnly
End If
Else '<~~ If not found
MsgBox "De ingevoerde gegevens zijn onjuist. Probeer het opnieuw.", vbOKOnly
End If
CleanExit:
Set ws = Nothing
Application.ScreenUpdating = True
Exit Sub
ErrorHandler:
MsgBox Err.Description
Resume CleanExit
End Sub
Now I need the code to have the sheets copied based on the input in txtLogin.