在 Excel 链接到 Google 财务的单元格中的数据是否有干扰 range.value 代码的额外信息?

In Excel Has Data in a Cell that is linked to Google Finance have extra information that interferes with code for range.value?

我有一个 linked 到 Google Finance Stock Ticker 的单元格。它用股票名称和包含的 link(银行图标)替换 Ticker,以显示更多数据。我希望使用 .value 或 value2 将股票名称添加到范围单元格中。但我认为附加数据中包含的 link 会干扰该功能。它 return 是一个错误代码 2015。我已经能够让它使用 .formula 添加股票名称,但因为我的范围还包括另一列,该列需要 .value 到它的单元格的 return 值。我不知道如何让两者的价值发挥作用。

这是 .Value 的直接 window 结果 错误 2015 2440 错误 2015 1945.2

这是 .Formula 的直接 window 结果 iShares纳斯达克100 Idx ETF (C-H) (XTSE:XQQ) =F6J6 iShares安硕S&P/TSX 60指数ETF (XTSE:XIU) =F7J7

代码如下:

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

为了演示使用两个相同大小的数组:

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