值未存储在动态数组中

时间:2016-04-20 13:51:54

标签: excel excel-vba vba

之前它工作正常,但现在数据不存储在数组中,同样存储在rng1中 我可以通过 ?rng1(1,1)或?rng1(39,4) 检查dubug窗口,但是vArray会给出错误的下标范围。

Dim vArray() As Variant
Dim rng1 As Range
Dim ShNm As String
Dim lROW AS LONG 

ShNm = Sheets("Main").Range("G3")

lRow = Worksheets(ShNm).Cells(Rows.Count, 1).End(xlUp).Row 

Set rng1 = Worksheets(ShNm).Range("A1:D" & lRow)

vArray = Worksheets(ShNm).Range("A1:D" & lRow)
or        
vArray = Worksheets(Sheets("Main").Range("G3")).Range("A1:D39")
or
vArray = Worksheets("ListofSheets").Range("A1:D39")

1 个答案:

答案 0 :(得分:1)

试试这个:

vArray = Worksheets("ListofSheets").Range("A1:D39").Value2