单元格中的数组不是连续的

时间:2015-11-11 14:50:02

标签: arrays excel-vba multidimensional-array vba excel

创建一个数组,一个范围是基本的

dim arr as range
arr = range("A1:A10)

我测试使用UNION从2个单元格区域中创建一个数组,但此函数仅运行到修改单元格属性,以便将数组粘贴到另一个范围内。 这是我的exaple,col A是值col B的结果。 enter image description here

我的代码:

Sub FuseRangeToArray()
    Dim ra As Range
    Dim rb As Range
    Dim rc As Range
    Dim a1 As Range
    Set ra = Range("A1:A10")     'the range is setting only for this exaple normally I pass it when I call my function
    Set rb = Range("A20:A29")    'idem
    Set rc = Union(ra, rb)
    rc.Select
    With Selection
        .Interior.Color = vbGreen
    End With
    Range("C1:C20") = rc.Value '20 is the count of all record, usually I use C:lastRow)

End Sub

我可以使用2范围的循环填充数组,但我寻找另一种方式

0 个答案:

没有答案