我一直在
运行时错误'9':下标超出范围
我试图让用户确定他们想要从QUANDL下载什么股票
Dim stock1 As Variant
Dim stock2 As Variant
Dim i As Integer
Dim stock() As Variant
ReDim stock(i) As Variant
stock1 = InputBox("Stock? Enter all in uppercase")
stock2 = InputBox("Stock?")
Range("B2").Value = "YAHOO/" & stock1 & "/6"
Range("C2").Value = "YAHOO/" & stock2 & "/6"
For i = 3 To 30
If stock(i) = InputBox("Stock?") Then
Range(Cells(2, 1 + i)) = "YAHOO/" & stock(i) & "/6"
ElseIf stock(i) = "last" Then
Exit For
End If
Next i
If stock(i) = inputbox("Stock?") Then
行不断收到错误。
答案 0 :(得分:1)
在i
语句中使用之前,您尚未为ReDim
分配任何值。未分配的整数具有Empty
或0
值:
将数组重新定义为i
,其中每个上面都有一个空/ 0值:
ReDim stock(i) As Variant
相当于:
ReDim stock(0) As Variant
因此,在你的循环中,任何大于0的i
值都会引发该错误。