VBA formula and text in a specific cell

I am trying to have some vba code to put the value of a formula and text in a specific cell. I want the code to speak. Leads: (formula value). Currently, my code runs the formula and puts the value in the correct field. I just don't know how to add text with it. The code I have is written below.

ws.Range("$B$1").Formula = "=COUNTIF(E:E,""Lead"")"
+4
source share
2 answers

The Range.NumberFormat custom property will give you the displayed result, leaving the actual raw value in numerical form for possible further calculations or comparisons.

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
+5
source

Try the following:

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

:

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

Source: https://habr.com/ru/post/1628357/


All Articles