I’ve got an Excel spreadsheet, with a Macro, that inserts a conditional formatting, like this:
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=UND($A3=""" & lastName & """; $B3=""" & firstName & """)"
As you can see, I’ve used the German formula for “AND” (i.e. “UND”), and obviously, this code doesn’t work as soon as I use it on a French or English version of Excel.
Usually formulas are localized automatically, but how can I insert a formula during run-time that will work on ALL versions?
Ok, thanks for helping me with this, you’ve helped me crack this one.
It is indeed not possible to just use English. One can use English when operating on a formula, eg. by setting coding
Range("A1").formula="AND(TRUE)", but this does not work withFormatConditions.My solution is a function that writes a formula temporarily to a cell, reads it through the
FormulaLocalproperty, and returns the localized formula, like so:The returned formula can be used on
FormatConditions, which will be re-localized or un-localized when the document is later opened on a different-language version of Excel.