在数组中的多个数组上循环
Loop on multiple arrays in an array
我有多个数组需要在 sheet 上打印。
我的想法是:
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
有办法吗?否则我将需要为每个 table.
重新复制和重复使用相同的代码
提前致谢
请尝试下一个改编代码:
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
它 returns 在 Immediate Window
。发送大量消息可能会很烦人...
要查看 Immediate Window
,请按 Ctrl + G
,在 VBE 中。
我有多个数组需要在 sheet 上打印。 我的想法是:
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
有办法吗?否则我将需要为每个 table.
重新复制和重复使用相同的代码提前致谢
请尝试下一个改编代码:
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
它 returns 在 Immediate Window
。发送大量消息可能会很烦人...
要查看 Immediate Window
,请按 Ctrl + G
,在 VBE 中。