特定单元格中的VBA公式和文本

时间:2021-11-12 22:18:57

I am trying to have some vba code to place the value of a formula and text into a specific cell. I want the code to say Leads:(value of formula). Currently my code runs the formula and places the value in the correct box. I just do not know how to add the text with it. The code I have is written below.

我正在尝试使用一些vba代码将公式和文本的值放入特定的单元格中。我希望代码说Leads :(公式的值)。目前我的代码运行公式并将值放在正确的框中。我只是不知道如何用它添加文本。我的代码写在下面。

ws.Range("$B$1").Formula = "=COUNTIF(E:E,""Lead"")"

2 个解决方案

#1


5  

A custom Range.NumberFormat property will give you the displayed result while leaving the actual raw value in a numerical form for possible further computation or comparison.

自定义Range.NumberFormat属性将为您显示结果,同时将实际原始值保留为数字形式,以便进一步计算或比较。

with ws
    with .range("B1")    '<~~ no need for absolute $ anchors here
        .formula = "=COUNTIF(E:E,""Lead"")"
        .numberformat = "[=1]L\e\a\d\: 0;L\e\a\d\s\: 0"
    end with
end with

#2


4  

Try this:

尝试这个:

ws.Range("$B$1").Formula = "=""Leads:("" & COUNTIF(E:E,""Lead"")&"")"""

so that it ends up like the following when applied:

因此在应用时它会像以下一样结束:

="Leads:(" & COUNTIF(E:E,"Lead")&")"

#1


5  

A custom Range.NumberFormat property will give you the displayed result while leaving the actual raw value in a numerical form for possible further computation or comparison.

自定义Range.NumberFormat属性将为您显示结果,同时将实际原始值保留为数字形式,以便进一步计算或比较。

with ws
    with .range("B1")    '<~~ no need for absolute $ anchors here
        .formula = "=COUNTIF(E:E,""Lead"")"
        .numberformat = "[=1]L\e\a\d\: 0;L\e\a\d\s\: 0"
    end with
end with

#2


4  

Try this:

尝试这个:

ws.Range("$B$1").Formula = "=""Leads:("" & COUNTIF(E:E,""Lead"")&"")"""

so that it ends up like the following when applied:

因此在应用时它会像以下一样结束:

="Leads:(" & COUNTIF(E:E,"Lead")&")"