試試看
Sub ex()
Dim Key$, C$, X%, S_NO
Dim A As Variant
Key = [AG5]
S_NO = [AG3]
C = Dir([AG1] & [AG2])
Do While C <> ""
With Workbooks.Open([AG1] & C)
With Workbooks(C).Worksheets(S_NO)
For Each A In .Range(.[c5], .[c5].End(4))
If A Like "*" & Key Then
For X = 1 To 10 Step 2
If .Range(A.Address).Offset(, X) <> "" Then
.Range(A.Address).Offset(, X + 1) = .Range(A.Address).Offset(, X)
.Range(A.Address).Offset(, X) = ""
End If
Next
End If
Next
End With
Application.DisplayAlerts = False
Workbooks(C).Close True
Application.DisplayAlerts = True
End With
C = Dir
Loop
End Sub作者: PJChen 時間: 2021-2-25 21:52