Excel Macro, inserting internationally valid formula during run-time

前端 未结 6 714
无人共我
无人共我 2020-12-01 15:59

I\'ve got an Excel spreadsheet, with a Macro, that inserts a conditional formatting, like this:

Selection.FormatConditions.Add Type:=xlExpression, Formula1:=         


        
6条回答
  •  臣服心动
    2020-12-01 16:40

    Thanks everyone! I found the post very useful.

    My solution is a combination of others, I add it in case somebody finds it useful.

    Dim tempform As String
    Dim strlocalform1 As String
    Dim strlocalform2 As String
    
    ' Get formula stored in WorksheetA Cell O1 =IFERROR(a,b)
    tempform = Worksheets("Sheet").Range("O1").Formula
    
    ' Extract from the formula IFERROR statement in local language.
    strlocalform1 = Mid(tempform, 2, InStr(1, tempform, "(") - 1)
    
    ' Extract from the formula separator , (comma) in local settings.
    strlocalform2 = Mid(tempform, InStr(1, tempform, "a") + 1, 1)
    
    ' Add formula in local language to desired field.
    pvt.CalculatedFields.Add Name:="NewField", Formula:="=" & strlocalform1 & "FORMULA" & strlocalform2 & ")"
    

    Hope this helps!

提交回复
热议问题