salifgotem
salifgotem

Reputation: 75

Can't combine text and formula in VBA?

I get a compilation error but it's well written I think ...

RangeBb.Formula "=Fait le '" & TODAY() & "' à Saint-Cyr-L'École,"

Upvotes: 0

Views: 44

Answers (2)

buran
buran

Reputation: 14233

RangeBb.Formula = "=""Fait le "" & TEXT(TODAY(), ""dd.mm.yyyy"") & "" a Saint-Cyr-L'Ecole,"""

Note that you need to wrap TODAY() in TEXT() in order to display the date properly.

The formula will be:

="Fait le " & TEXT(TODAY(), "dd.mm.yyyy") & " a Saint-Cyr-L'Ecole,"

and the display text in the cell:

Fait le 09.02.2023 a Saint-Cyr-L'Ecole,

Upvotes: 3

Dominique
Dominique

Reputation: 17493

This is what I get when I enter this inside a cell and record the macro:

ActiveCell.FormulaR1C1 = "=""Fait le"" & TODAY() & ""ici"""

Upvotes: 2

Related Questions