Question

I'm using polish Excel so "R[-2]C" is "W[-2]C".

In every place I tried VBA only accepted RC notation. Which is good since it will work regardless of language version of Excel.

But for conditional formatting only "W[-2]C" works.

  • Q: Will "W[-2]C" notation work in non-polish version of Excel?
  • Q: What alternative is there for it?

Edit:

Here is the code that works for MY language version:

.FormatConditions.Delete
.FormatConditions.add Type:=xlExpression, Formula1:="=WK[-2]-WK[-1]<WK"
With .FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .ThemeColor = xlThemeColorAccent2
    .TintAndShade = 0
End With
Was it helpful?

Solution

Language independent Excel formulae for use in conditional formatting or validation rules

Write your formula with english function names, with either A1- or R1C1-references. Assign this formula as the cell formula to an appropriate cell. This could be the cell you are about to format, or any unused cell. Then read the FormulaLocal from that cell - this is the formula you are going to use for formatting. Set the formula of the cell you used as translator to blank.

OTHER TIPS

In addition to Anonymous Type's answer, here's an actual implementation which you can use as a utility:

' Rewrites the given formula from English to the current locale.
' This can be useful when working with conditional formatting expressions,
' where Excel only accepts localized formulas for some reason.

' For this function to work, you must supply a cell which can be used for
' generating the formula. This cell will be cleared after the operation, so
' avoid cells which contain any meaningful data - use a temporary sheet if
' you already have one.
Public Function ConvertToLocalizedFormula(formulaToConvert As String, _
                                          notationToUse As XlReferenceStyle, _
                                          ByRef tempCell As Range _
                                          ) As String


    If notationToUse = xlR1C1 Then
        tempCell.FormulaR1C1 = formulaToConvert
        ConvertToLocalizedFormula = tempCell.FormulaR1C1Local
    Else
        tempCell.formula = formulaToConvert
        ConvertToLocalizedFormula = tempCell.FormulaLocal
    End If
    tempCell.Clear
End Function

As an example, using this with the Hungarian locale in Immediate gives the following:

Debug.Print ConvertToLocalizedFormula("=SUM($H5:$AE24)", xlA1, ActiveSheet.Range("AJ1"))
=SZUM($H5:$AE24)

Debug.Print ConvertToLocalizedFormula("=SUM(R5C7:R5C9)", xlR1C1, ActiveSheet.Range("AJ1"))
=SZUM(S5O7:S5O9)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top