0

我需要将数据从 Excel 范围复制到数组中。我正在使用以下代码,但它显示错误“预期数组”。

  Dim filename As String
  Dim arraysize As Integer

  arraysize = 50
  I = 1
  Do Until ThisWorkbook.Sheets("sheet1").Cells(I, 1).Value = ""   
     filename(arraysize) = ThisWorkbook.Sheets("sheet1").Cells(I, 1).Value    
     I = I + 1
  Loop
4

2 回答 2

1

尝试这个

Sub Demo()
    Dim filename As Variant
    Dim arraysize As Long
    Dim rng As Range
    Dim i As Long

    i = 1
    With ThisWorkbook.Sheets("sheet1")
        Set rng = .Range(.Cells(i, 1), .Cells(i, 1).End(xlDown))
    End With

    ' load as two dimensional array
    filename = rng.Value

    ' transform into 1 dimensional array
    filename = Application.Transpose(filename)

    arraysize = UBound(filename)
End Sub
于 2013-02-14T04:50:30.960 回答
-1

你还没有声明数组。我想不出脑海中的代码,但这应该为您指明正确的方向。

Dim Filename(50)

Do
    Filename(I)= excel.row
Loop
于 2013-02-14T04:29:58.883 回答