Sub Test0801()
All = Array("三商", "遠東", "信義")
Rn = [A1].End(4).Row
For R = 1 To Rn
B = Application.Match(Cells(R, 2), All, 0)
If Not IsError(B) Then '地點是否在All陣列內
With Sheets(Cells(R, 2).Value)
Ro = .Cells(Rows.Count, 1).End(3).Row '找每頁最末列
If Ro = 1 And .[A1] = "" Then Range([A1], [A1].End(2)).Copy .[A1] '複製標提列
Ro = Ro + 1: Range(Cells(R, 1), Cells(R, 1).End(2)).Copy .Cells(Ro, 1) '複製資料
End With
End If
Next
End Sub
請問 那如果要讓 A = Array("三商", "遠東", "信義") 變成動態有彈性 該如何寫呢?
要先下邏輯,除了本身工作表以外的工作表都納入A陣列,可以這樣寫
Dim A(): K = -1
For Each sh In Sheets
If sh.Name <> ActiveSheet.Name Then
K = K + 1: ReDim Preserve A(K)
A(K) = sh.Name
End If
Next作者: n7822123 時間: 2020-8-2 16:48