我有多個陣列需要列印在一張紙上。我的想法是:
tables = array("table1","table2",....)
for z= lbound(tables,1)to ubound(tableaux,1)
for j= lbound(tables(z),1)to ubound(tables(z),1)
for k= lbound(tables(z),2)to ubound(tables(z),2)
msg tables(z)(j,k)
next
next
next
有沒有辦法做到這一點?否則我將需要為每個表重新復制和重用相同的代碼。
提前致謝
uj5u.com熱心網友回復:
請嘗試下一個改編的代碼:
Sub LoopInTablesArrays()
Dim tables, tbl1 As ListObject, tbl2 As ListObject, table1, table2
Dim z As Long, j As Long, k As Long
Set tbl1 = ActiveSheet.ListObjects("Table23") 'use here an existing table sheet/name
Set tbl2 = ActiveSheet.ListObjects("Table26") 'set an existing table
table1 = tbl1.Range.value 'place the table range in an array
table2 = tbl2.Range.value 'place the table range in an array
tables = Array(table1, table2) 'you may place here as many arrays as you need
For z = LBound(tables, 1) To UBound(tables, 1)
For j = LBound(tables(z), 1) To UBound(tables(z), 1)
For k = LBound(tables(z), 2) To UBound(tables(z), 2)
Debug.Print tables(z)(j, k)
Next k
Next j
Next z
End Sub
它回傳Immediate Window. 發送大量訊息可能很煩人...
要查看Immediate Window,請按Ctrl G,處于 VBE 中。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/483806.html
