原程式碼添加如下:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.EnableEvents = False
If Left(Target.Address(0, 0), 1) = "A" Then
ElseIf Left(Target.Address(0, 0), 1) = "B" Then
If Cells(Target.Row, 2) = "貼上文號" Then
[B1] = ""
For i = 0 To 5000
If Cells(3 + i, 2) = "" Then
Cells(3 + i, 2).Select
ActiveSheet.PasteSpecial xlPasteValues
[B1] = "完成"
'判斷是否重複複製
If Cells(3 + i, 2) = Cells(2 + i, 2) Then
[B1] = "重複複製"
Cells(3 + i, 2) = ""
End If
Application.EnableEvents = True: Exit Sub
End If
Next
End If
ElseIf Left(Target.Address(0, 0), 1) = "C" Then
If Cells(Target.Row, 3) = "貼上名字" Then Application.EnableEvents = True: Exit Sub
ElseIf Left(Target.Address(0, 0), 1) = "D" Then
If Cells(Target.Row, 4) = "搜尋文號 ↑↑↑" Then [D1].Select
ElseIf Left(Target.Address(0, 0), 1) = "E" Then
If Cells(Target.Row, 5) = "複製文號" Then [D1].Select
ElseIf Left(Target.Address(0, 0), 1) = "F" Then
If Cells(Target.Row, 6) = "複製名字" Then [D1].Select
ElseIf Left(Target.Address(0, 0), 1) = "G" Then
If Cells(Target.Row, 7) = "搜尋名字 ↑↑↑" Then [G1].Select
End If
Application.EnableEvents = True
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Target.Address(0, 0) = "D1" Then
If [D1] = "" Then ActiveSheet.Range("E2").AutoFilter Field:=1: Application.EnableEvents = True: Exit Sub
[G1] = ""
'搜尋文號
Range("E2").AutoFilter Field:=1, Criteria1:="*" & Target & "*"
ActiveWindow.ScrollRow = 1
ElseIf Target.Address(0, 0) = "G1" Then
If [G1] = "" Then ActiveSheet.Range("F2").AutoFilter Field:=2: Application.EnableEvents = True: Exit Sub
[D1] = ""
'搜尋名字
Range("G2").AutoFilter Field:=2, Criteria1:="*" & Target & "*"
ActiveWindow.ScrollRow = 1
End If
Application.EnableEvents = True
End Sub