Excel VBA使用本地化的RC公式来进行条件格式化?

我正在使用波兰语Excel,所以“R [-2] C”是“W [-2] C”。

在我尝试过的每一个地方,VBA只接受RC符号。 这是好的,因为它可以工作,不pipe语言版本的Excel。

但是对于条件格式,只有“W [-2] C”起作用。

  • 问:“W [-2] C”符号是否在非抛光版Excel中工作?
  • 问:还有什么替代方法?

编辑:

以下是适用于我的语言版本的代码:

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

语言独立的Excel公式,用于条件格式或validation规则

用英文函数名写公式,用A1或R1C1引用。 将此公式作为单元格公式分配给适当的单元格。 这可能是您要格式化的单元格,或任何未使用的单元格。 然后从该单元格中读取FormulaLocal – 这是您要用于格式化的公式。 将您用作翻译器的单元格的公式设置为空白。

除了匿名types的答案,这是一个实际的实现,你可以用作一个工具:

 ' 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 

举个例子,在Immediate中使用匈牙利的语言环境,可以得到以下结果:

 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)