合并阵列多张纸

时间:2019-03-14 08:21:07

标签: arrays vba worksheet-function

请告知我如何才能获得昏暗的床单,因为有时会超过300张,并且并非每张床单的名称都为(sheet4)。我将不得不合并同一阵列R10C1:R26C2

Sub Macro15()

Dim wb As Workbook
Dim ws As Worksheet
Dim ws2 As Worksheet
Dim arrRange()

Set wb = ThisWorkbook
Set ws = wb.ActiveSheet

arrRange = Array("Sheet4!R10C1:R26C2", "Sheet4 (2)!R10C1:R26C2", "Sheet4 (3)!R10C1:R26C2", _
"Sheet4 (4)!R10C1:R26C2", "Sheet4 (5)!R10C1:R26C2", "Sheet4 (6)!R10C1:R26C2", "Sheet4 (7)!R10C1:R26C2", _
"Sheet4 (8)!R10C1:R26C2", "Sheet4 (9)!R10C1:R26C2", "Sheet4 (10)!R10C1:R26C2", "Sheet4 (11)!R10C1:R26C2", _
"Sheet4 (12)!R10C1:R26C2", "Sheet4 (13)!R10C1:R26C2", "Sheet4 (14)!R10C1:R26C2")

Set ws2 = wb.Sheets.Add

With ws2
    .Range("A1").Consolidate arrRange, xlSum, True, True, False
End With

Application.ActiveWindow.SmallScroll Down:=-228
ws.Columns("A:A").ColumnWidth = 23.88
ws.Columns("A:A").ColumnWidth = 41.25
ws.Columns("A:A").ColumnWidth = 47.88
ws.Columns("B:B").ColumnWidth = 16.5

End Sub

1 个答案:

答案 0 :(得分:0)

未经测试:但是您可以尝试使用类似方法获取工作表名称,并将工作表名称复制到数组中时将范围连接到该表。

Dim sheets_Count As Integer
Dim sheets_Name() As String

sheets_Count = Sheets.Count

ReDim sheets_Name(sheets_Count)

For i = 1 To sheets_Count
    sheets_Name(i) = ActiveWorkbook.Sheets(i).Name
Next i

end sub

希望有帮助。