我将43个股票代码历史价格下载到excel 2013.我的代码使用了一个二维数组,然后将其转置并插入到工作表中。它工作正常,直到我尝试下载定价回溯到1990年的43个symobls。似乎一旦数组的第二维超过一定量,单元格值就会转向#N / A,因为某些指向第一列。关于锯齿状数组(嵌套数组)的任何想法,但我将如何循环以产生我需要的输出范围?感谢所有的建议。
RERFX RFNCX RWICX SASMX SGRKX SGRKX SMGIX TRSGX VETAX VIMAX VINIX VIPSX VSCAX WACPX WAPAX WASAX 5/15/2002 6/4/2002 6/6/2002 1/1/2001 8/30/2002 8/30/2002 1/1/2001 1/1/2001 5/5/2000 11/12/2001 1/1/2001 6/29/2000 1/1/2001 1/1/2001 5/21/2012 5/21/2012
这些是符号和日期。我为所有符号创建了一个范围,然后通过在符号本身之外创建范围来创建开始日期。
Sub GetDailyReturnsTest()
Dim URL As String, today As String, http As Object, csv As String, temp() As String
Dim txt As String, r As Integer, a As Single, b As String, s As Double, ticker As Variant, icountSymbol As Integer, sTicker As String
Dim iSymbol As Integer, dateParams As String, t As Double, sym As range
Application.ScreenUpdating = False
Set ticker = Application.[fundsymbols]
icountSymbol = ticker.Count
ReDim temp(8, 0)
today = Date
For Each sym In ticker
dateParams = "&a=" & Month(range(sym)) - 1 & "&b=" & Day(range(sym)) & "&c=" & Year(range(sym)) & "&d=" & Month(Now) & "&e=" & Day(Now) & "&f=" & Year(Now)
sTicker = ticker(1, iSymbol)
URL = "http://ichart.finance.yahoo.com/table.csv?s=" & sTicker & dateParams & "g=d&ignore=.csv"
On Error Resume Next
Set http = CreateObject("msxml2.xmlhttp")
http.Open "get", URL, False
http.send
csv = http.ResponseText
r = 0
txt = ""
For a = 1 To Len(csv)
b = Mid(csv, a, 1)
If b = "," Then
temp(r, UBound(temp, 2)) = txt
r = r + 1
txt = ""
ElseIf b = Chr(10) Then
temp(r, UBound(temp, 2)) = txt
r = r + 1
txt = sTicker
temp(r, UBound(temp, 2)) = txt
ReDim Preserve temp(UBound(temp, 1), UBound(temp, 2) + 1)
txt = ""
r = 0
Else
txt = txt & b
End If
Next a
Next sym
Worksheets("FundsHistoricalPricing").Activate
On Error Resume Next
With ActiveSheet.Cells
.ClearContents
.ClearFormats
End With
range("a2").Resize(UBound(temp, 2) + 1, UBound(temp, 1)).Value = Application.Transpose(temp)
end sub