将Bloomberg公式插入单元格

时间:2018-11-19 20:34:32

标签: excel vba excel-vba syntax excel-formula

我希望将第32行的公式输入到单元格中,但是无法运行或编译我的代码。必须有一个引号错误或语法,我无法理解。有人可以解释一下运行此代码的问题吗?

谢谢你, 欧里

Sub Ticker_Update()

Dim subSector As String
Dim Ticker As String

Dim bRow As Double
Dim tRow As Double

Dim bRow1 As Double

Application.ScreenUpdating = False

With ThisWorkbook.Worksheets("SectorSort")

Range("C8:AA1000").Clear
subSector = Range("B6").Value

Worksheets("Canadian").Activate
    With ThisWorkbook.Worksheets("Canadian")

        tRow = 4
        bRow = Cells(Rows.Count, "C").End(xlUp).row

        Do While tRow <= bRow

            If Cells(tRow, "C").Value = subSector Then
                Ticker = Cells(tRow, "B").Value

                Worksheets("sectorSort").Activate
                    bRow1 = .Cells(Rows.Count, "C").End(xlUp).row + 1
                    .Cells(bRow1, "C") = Ticker
                    .Cells(bRow1, "D").Formula = "=BDS($C8,"CHAIN_TICKERS","CHAIN_STRIKE_PX_OVRD=ATM","CHAIN_EXP_DT_OVRD",TEXT(D$7,"YYYYMMDD"),"CHAIN_PERIODICITY_OVRD=ALL")"

                Worksheets("Canadian").Activate

                tRow = tRow + 1

            Else
                tRow = tRow + 1
            End If

    Loop

    End With

    Worksheets("SectorSort").Activate

End With


End Sub

1 个答案:

答案 0 :(得分:1)

在公式中使用双引号""

.Cells(bRow1, "D").Formula = "=BDS($C8,""CHAIN_TICKERS"",""CHAIN_STRIKE_PX_OVRD=ATM"",""CHAIN_EXP_DT_OVRD"",TEXT(D$7,""YYYYMMDD""),""CHAIN_PERIODICITY_OVRD=ALL"")"