错误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
答案 0 :(得分:2)
假设您的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
引用都未指定工作表或工作簿,这意味着它们将引用代码运行时活动的任何工作簿和工作表。讲,您不想要这个,但这不是您的问题。)