在LOOP上使用Bloomberg函数的VBA问题

时间:2017-08-25 11:38:21

标签: database vba bloomberg

我正在尝试使用此代码以两个单元格的步骤将A2中的公式引入数据库的末尾。

        foreach (var item in pictureList)
        {
            pictures pc = new pictures();
            //...

            pc.comments = new List<comments>();
            //linq to get comments here
            pc.comments.Add(new comments());

            pc.likes = new List<likes>();
            //linq to get likes
            pc.likes.Add(new likes());

            pictureList.Add(pc);
        };

问题是我的指令出错:

Sub addbdh()

Dim i As Integer
Dim n As Integer

Range("A3").Select
Range(Selection, Selection.End(xlToRight)).Select

n = Selection.Count

For i = 1 To n

Cells(3, i * 2 - 1).Formula = "BDH(""A"" & "i * 2 - 1", "A1", "B1, "hoy()")"

Next i

End Sub

特别是在“i * 2 - 1”部分,我得到一个Excel MsgBox,上面写着“期待的结​​束声明”(西班牙文:“se esperaba:fin delacinstrucción”。

¿有人可以帮我找到代码上的错误吗?

坦克你。

1 个答案:

答案 0 :(得分:0)

一般情况下,.Formula会显示真实的英语公式。无论你的语言是什么。因此,Hoy()应更改为Today()

一般情况下,请尝试这样:

Cells(3, i * 2 - 1).Formula = "=BDH(A" & i * 2 - 1 & ", A1, B1, Today())"

一般情况下,遇到类似&#34;如何将工作的Excel公式转换为VBA&#34;执行以下操作:

  1. 在Excel中选择工作公式。
  2. 运行以下代码。
  3. 从即时窗口中取出公式并稍加修正以放置变量i * 2 - 1
  4. Public Sub PrintMeUsefulFormula()
    
        Dim strFormula  As String
        Dim strParenth  As String
    
        strParenth = """"
    
        strFormula = Selection.Formula
        strFormula = Replace(strFormula, """", """""")
    
        strFormula = strParenth & strFormula & strParenth
        Debug.Print strFormula
    
    End Sub