|
Sub 批量操作()
Application.ScreenUpdating = False
Dim ar As Variant
Dim br()
lj = ThisWorkbook.Path & "\"
f = Dir(lj & "*.xls*")
Do While f <> ""
If f <> ThisWorkbook.Name Then
Set wb = Workbooks.Open(lj & f, 0)
With wb.Worksheets(1)
r = .Cells(Rows.Count, 3).End(xlUp).Row
ar = .Range("a1:f" & r + 2)
n = 1
ReDim br(1 To UBound(ar), 1 To UBound(ar, 2))
m = 0
For j = 1 To UBound(ar, 2)
If j <> 4 Then
m = m + 1
br(1, m) = ar(1, j)
End If
Next j
For i = 2 To r
If ar(i, 1) <> "" Then
n = n + 1
For j = 1 To 2
br(n, j) = ar(i, j)
Next j
br(n, 3) = ar(i, 3) - ar(i + 2, 4)
For j = 5 To 6
br(n, j - 1) = ar(i, j)
Next j
br(n, 6) = br(n, 1) & br(n, 2)
End If
Next i
.[a1].CurrentRegion = Empty
.[a1].Resize(n, UBound(br, 2)) = br
End With
wb.Close True
End If
f = Dir
Loop
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|