|
楼主 |
发表于 2018-7-16 15:55
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub test()
- Dim r%, i%
- Dim arr, brr, vs(1 To 3)
- Dim wb As Workbook
- Dim ws As Worksheet
- Dim mypath$, myname$
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- vs(1) = [{5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,25,26,28,29,32}]
- vs(2) = [{5,6,7,8,9,10,11,12,48,49,50,51,52,56,57,60,61,62,65}]
- vs(3) = [{23,32}]
- With Worksheets("sheet1")
- dm = .Range("g1")
- arr = .Range("a3:g26")
- End With
- mypath = ThisWorkbook.Path & ""
- wjj = "1806-" & dm & "报表"
- If Dir(mypath & wjj, vbDirectory) = "" Then
- MsgBox mypath & wjj & "不存在!"
- Exit Sub
- End If
- k = 0
- For Each aa In Array("1806-" & dm & "C表", "1806-" & dm & "B表", "1806-" & dm & "资产负债表")
- k = k + 1
- wjm = mypath & wjj & "" & aa & ".xls"
- If Dir(wjm) <> "" Then
- Set wb = GetObject(wjm)
- With wb
- With .Worksheets("汇总")
- Select Case k
- Case 1
- brr = .Range("a1:m34")
- Case 2
- brr = .Range("a1:m65")
- Case 3
- brr = .Range("a1:f39")
- End Select
- For j = 1 To UBound(vs(k))
- If k <= 2 Then
- arr(j, k * 2) = brr(vs(k)(j), 3)
- Else
- arr(j, 6) = brr(vs(k)(j), 2)
- arr(j, 7) = brr(vs(k)(j), 3)
- End If
- Next
- End With
- .Close False
- End With
- End If
- Next
- With Worksheets("sheet1")
- .Range("a3").Resize(UBound(arr), UBound(arr, 2)) = arr
- End With
- End Sub
复制代码 感谢 chxw68 提供帮助!
|
|