代码之家  ›  专栏  ›  技术社区  ›  SantiClaus

为什么会出现错误“应用程序定义的错误或对象定义的错误”?

  •  0
  • SantiClaus  · 技术社区  · 7 年前

    错误在哪里 application-defined or object defined error 来自哪里?它似乎来自我创造的公式。请帮忙。用VBA编写代码确实不应该这么难,但由于某些原因,它不起作用。

    Sub get_levels()
    
        Dim Count As Integer
        Dim ticker As Variant
        Dim lastRow As Long
        Dim lastRowC As Long
        Dim rng As Range
        Dim current_input_position As Long
        Dim sheet As String
        Dim mula As String
        Dim updatedTicker As String
    
        Application.CutCopyMode = False
        Count = 0
        sheet = "Test_Sheet"
    
        current_input_position = 2
    
        lastRow = Cells(Rows.Count, "A").End(xlUp).row
    
        Label:
    
        Set rng = Range("A" & current_input_position & ":A" & lastRow)
        For Each ticker In rng.Cells
    
            lastRowC = Cells(Rows.Count, "C").End(xlUp).row
            updatedTicker = ticker & " A" & " Mtge"
    
            MsgBox updatedTicker 
    
            mula = "GCBDC 2018-1A A Mtge"
    
            Range("E2").formula = "=BDS(" & mula & ",""MTGE_CMO_GROUP_LIST"",""Headers=N"")"
    
        Next ticker
    
    
    End Sub
    
    1 回复  |  直到 7 年前
        1
  •  2
  •   chillin    7 年前

    假设您的Bloomberg插件功能正常(请尝试调用 BDS 从常规工作表手动检查),我认为您可能需要更改此行:

    Range("E2").formula = "=BDS(" & mula & ",""MTGE_CMO_GROUP_LIST"",""Headers=N"")"

    Range("E2").Formula = "=BDS(""" & mula & """,""MTGE_CMO_GROUP_LIST"",""Headers=N"")"

    如果你的变量 mula " 两边都有。

    Range Cells