使用VBA将多个公式放在一个单元格中 [英] Using VBA to place multiple formulas in one cell

查看:281
本文介绍了使用VBA将多个公式放在一个单元格中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用宏来将多个公式放在一个单元格中。在这种情况下,它的3彭博公式成一个单元格。当在VBA模块中键入它时,该公式在Excel中复制或键入时,在Excel中创建错误(Compile error:Expected:End of statement),并突出显示rtg_mdy_sen_unsecured_debt。我相信问题是在公式中使用引号,但我找不到任何有关如何解决它的信息。

I'm working on a macro to place multiple formulas in one cell. In this case, its 3 Bloomberg formulas into one cell. The formula works in Excel when copied or typed manually but not when type it in the VBA module, where it creates an error (Compile error: Expected: End of statement) and highlights "rtg_mdy_sen_unsecured_debt". I believe the problem is the use of quotation marks in the formula but I can't find any information on how to work around it.

在Excel中工作的公式(当手动输入或复制到单元格中时):

= BDP($ O4,rtg_mdy_sen_unsecured_debt)&/& BDP($ O4,rtg_sp_lt_lc_issuer_credit) &/& BDP($ O4,rtg_fitch_sen_unsecured)

The formula that works in Excel (when input manually or copied into a cell) follows:
=BDP($O4,"rtg_mdy_sen_unsecured_debt")&"/"&BDP($O4,"rtg_sp_lt_lc_issuer_credit")&"/"&BDP($O4,"rtg_fitch_sen_unsecured")

尝试以下格式时,它在VBA中不起作用:

It does not work in VBA when attempting the following format:

单元格(4,21).Value == BDP($ O4,rtg_mdy_sen_unsecured_debt)&/& BDP $ O4,rtg_sp_lt_lc_issuer_credit)&/& BDP($ O4,rtg_fitch_sen_unsecured)

($ O4引用一个包含BA Equity的单元格,Q2包含industry_sector)

Simpler Bloomberg formulas work just fine: ($O4 references a cell which contains "BA Equity". Q2 contains "industry_sector")

单元格(4,17)。 Value == BDP(O4,Q2)

所需的结束状态是,细胞(4,21)将显示波音的信用评级从三大评级一如下所示:A2 / A / A

The desired end state is that Cells(4, 21) will display Boeing's credit rating from the three major rating agencies, like this: A2/A/A

推荐答案

创建包含的VBA字符串字符,您必须用另一个分隔它们

这将适用于poseted字符串



This will work for the poseted string

Cells(4, 21).Value = _
"=BDP($O4,""rtg_mdy_sen_unsecured_debt"")&""/""&BDP($O4,""rtg_sp_lt_lc_issuer_credit"")&""/""&BDP($O4,""rtg_fitch_sen_unsecured"")"

这篇关于使用VBA将多个公式放在一个单元格中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆