我是VBA的新手,正尝试制作一个下拉列表,列出不同职位中人员的姓名(XXX,YYY,ZZZ等),然后您可以从列表中选择一个姓名,然后将其行从Sheet7中将该人的信息复制并粘贴到搜索栏所在的Sheet3中。我在这方面还没有成功,希望能有所帮助。我使该代码对本文的名称和职位更加通用。预先感谢。
Private Sub CommandButton1_Click()
'On Error GoTo Cleanup
Application.ScreenUpdating = False: Application.EnableEvents = False
With Sheet3
For i = .Cells(.Rows.Count, 3).End(xlup).Rows To 2 Step -1
Select Case .Cells(i, 3).Value = c
Case "XXX", "YYY", "ZZZ", "AAA", "BBB", "CCC", "DDD", "FFF", "GGG", "HHH", "III", "JJJ", "LLL", "MMM", "NNN"
.Rows(i).Copy
End Select
With Sheet3
Dim lastrow As Long
lastrow = Range("A65536").End(xlUp).Row
Worksheets(i).Activate
Cells(lastrow + 1, 1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End With
End With
'Cleanup:
'Application.ScreenUpdating = True: Application.EnableEvents = True
End Sub