|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub cmdImport_Click()
Application.ScreenUpdating = False
Dim FileNames
FileNames = Application.GetOpenFilename(filefilter:="Microsoft Excel文件(*.xlsx),*.xlsx", FilterIndex:=2, Title:="选择文件", MultiSelect:=True)
If TypeName(FileNames) = "Boolean" Then
Exit Sub
End If
ReDim arr(1 To 10000, 1 To 15)
Set xlSheet = Worksheets("台账数据")
With xlSheet
r = .Cells(Rows.Count, 1).End(xlUp).Row
.Range("A3:N" & r + 2).Clear
rs = .Cells(Rows.Count, 17).End(xlUp).Row
.Range("q11:r" & rs + 2).Clear
For i = LBound(FileNames) To UBound(FileNames)
f = FileNames(i)
Set WB = Workbooks.Open(f)
With WB.Worksheets(1)
ws = .Cells(Rows.Count, 1).End(xlUp).Row
ar = .Range("a1:o" & ws)
End With
WB.Close False
For s = 6 To UBound(ar)
If Trim(ar(s, 2)) = "XC" Then
n = n + 1
arr(n, 1) = n
For j = 2 To 6
arr(n, j) = ar(s, j)
Next j
arr(n, 7) = ar(s, 10)
arr(n, 8) = ar(s, 6)
arr(n, 9) = ar(s, 7)
arr(n, 10) = ar(s, 8)
For j = 11 To 14
arr(n, j) = ar(s, j)
Next j
End If
Next s
Next i
.[a3].Resize(n, 15) = arr
.[a3].Resize(n, 15).Borders.LineStyle = 1
End With
Application.ScreenUpdating = True
End Sub
|
|