0
我想讓我的VBA代碼在3列的表中做一個查找匹配,當它找到匹配時,它應該將正確的工作表複製到另一個文件。Vlookup在表中複製多個工作表
我有一個用戶名必須輸入用戶名。然後它匹配這個用戶名(列A)到單元格(列C)的單元名稱。我怎樣才能定義這個vlookup來匹配然後複製多個工作表。我應該如何格式化C列中的圖紙名稱?
我的表看起來像現在這樣右: A:使用者(例如, 「亞歷山大」) B:密碼(例如, 「測試1」) C:表(例如, 「表1,表2」)
謝謝!
編輯:
我輸入密碼授權當前的代碼,這是基於用戶窗體:
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
現在我需要的代碼有基於在txtLogin輸入複製的表。
如果你有代碼,您應該把它包含在你的問題中。究竟哪一部分給你帶來問題? –
已添加代碼。來自txtlogin vlookup的輸入複製代碼給我帶來了問題。我不知道如何啓動這個代碼。 – McKai