我有一个声明如下的数组:
MyArr = Sheets("xls").Range("A1:A" & last_row).Value2
我想添加另一个Range。范围(“D1:D”和< last_row).Value2到它,我该怎么做?
或...从非连续范围创建数组的任何简单方法?我需要一个没有空白的单维数组作为跟随范围的结果
Range("A1:A100") and Range("AL1:AM:120)
答案 0 :(得分:0)
一种方式:
Sub dural()
Dim ary() As Variant, i As Long
Dim r As Range
i = 1
For Each r In Union(Range("A1:A100"), Range("AL1:AM120"))
If r.Value <> "" Then
ReDim Preserve ary(1 To i)
ary(i) = r.Value
i = i + 1
End If
Next r
MsgBox i
End Sub