我有一個鏈接到 Google Finance Stock Ticker 的單元格。它將股票代碼替換為股票名稱,并包含一個鏈接(銀行圖示)以顯示更多資料。我希望使用 .value 或 value2 將股票名稱添加到范圍單元格中。但我認為包含的附加資料鏈接會干擾該功能。它回傳一個錯誤代碼 2015。我已經能夠讓它使用 .formula 添加股票名稱,但因為我的范圍還包括另一個需要 .value 來回傳其單元格值的列。我不知道如何讓兩者的價值發揮作用。
這是 .Value 錯誤 2015 2440 錯誤 2015 1945.2 的即時視窗結果
這是 .Formula iSharesNASDAQ100 Idx ETF (CH) (XTSE:XQQ) =F6 J6 iShares S&P/TSX 60 Index ETF (XTSE:XIU) =F7 J7的即時視窗結果
這是代碼:
arr = .Range(.Cells(6, "C"), .Cells(.Rows.Count, "D").End(xlUp)).Formula
Debug.Print arr(1, 1) ' which is C (column, row format)
Debug.Print arr(1, 2) ' which is column d
Debug.Print arr(2, 1) ' which is C (column, row format)
Debug.Print arr(2, 2) ' which is column d
我難住了。有什么幫助嗎?
For i = LBound(arr, 1) To UBound(arr, 1) ' Loop through and assign to dict.
k = arr(i, 1) 'the key
amt = arr(i, 2) 'the amount
Debug.Print arr(1, 1)
dict(k) = dict(k) amt 'sum amount for this key
Next i
'return new values to worksheet
.Cells(1, "W").Resize(1, 2) = Array("Company", "Value")
.Cells(2, "W").Resize(dict.Count, 1) = Application.Transpose(dict.Keys)
.Cells(2, "X").Resize(dict.Count, 1) = Application.Transpose(dict.items)
With .Range(.Cells(1, "W"), .Cells(.Rows.Count, "X").End(xlUp))
.Sort key1:=.Columns(2), order1:=xlDescending, _
key2:=.Columns(1), order2:=xlAscending, _
Header:=xlYes
End With
uj5u.com熱心網友回復:
演示使用兩個相同大小的陣列:
Dim lastRow As Long
lastRow = .Cells(.Rows.Count, "D").End(xlUp).Row
Dim formulas() As Variant
formulas = .Range("C6:C" & lastRow).Formula
Dim vals() As Variant
vals = .Range("D6:D" & lastRow).Value
Dim i As Long
For i = LBound(formulas, 1) To UBound(formulas, 1)
k = formulas(i, 1)
amt = vals(i, 1)
dict(k) = dict(k) amt
Next
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/410272.html
標籤:
上一篇:VBA文本框自動更正為日期格式
