我使用的是抛光Excel,所以"R-2C“是"W-2C”。
在我尝试过的每个地方,VBA只接受RC表示法。这很好,因为不管Excel的语言版本如何,它都能工作。
但条件格式只适用于"W-2C“。
编辑:
下面是适用于我的语言版本的代码:
.FormatConditions.Delete
.FormatConditions.add Type:=xlExpression, Formula1:="=WK[-2]-WK[-1]<WK"
With .FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent2
.TintAndShade = 0
End With发布于 2014-09-05 07:38:41
用于条件格式或验证规则的独立于语言的Excel公式
用英文函数名写出公式,或者用A1-或R1C1-引用。将此公式作为单元格公式分配给适当的单元格。这可能是要格式化的单元格,也可能是任何未使用的单元格。然后从该单元格中读取FormulaLocal --这是要用于格式化的公式。将用作翻译器的单元格的公式设置为空。
发布于 2015-10-06 10:38:11
除了匿名类型的答案之外,下面还有一个实际的实现,您可以将其用作实用程序:
' 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例如,将此与匈牙利地区联系在一起可得到以下结果:
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)https://stackoverflow.com/questions/23649293
复制相似问题