【发布时间】:2015-07-09 23:04:32
【问题描述】:
信不信由你,我搜索了 google、Stack、MSDN 并查看了无数的代码示例,这些示例提供了各种数组的示例。我可以获得简单的数组来处理 For...Next 循环;如下所示,但无论我如何构造下面的代码,我都无法让输出反映,以便每个代码在每个数组之间来回切换,一次一个变量。任何想法。
我必须在数组中创建一个数组吗?锯齿状阵列?我看过多维数组,它们似乎是正确的方法。但是,我不确定。
好的,现在投反对票并弃之不顾! -_-
Sub Array 123()
Dim myarray As Variant
Dim myarray2 As Variant
'Let's assume ranges a1, a2 and a3 contain values 1, 2 and 3 and that
'ranges a4, a5 and a6 contain values 4, 5 and 6
myarray = ThisWorkbook.Worksheets("sheet6").Range("a1:a3").Value
myarray2 = ThisWorkbook.Worksheets("sheet6").Range("a4:a6").Value
For i = 1 To UBound(myarray)
MsgBox myarray(i, 1)
Next i
For j = 1 To UBound(myarray2)
MsgBox myarray2(j, 1)
Next j
End Sub
'the out put will be:
[ 1 2 3 4 5 6 ]
'how would one arrange the structure of the code above so that the output is:
[ 1 4 2 5 3 6 ]
【问题讨论】: