=1,ISNUMBER(L11)),TRUE,IF(AND" /> =1,ISNUMBER(L11)),TRUE,IF(AND" /> =1,ISNUMBER(L11)),TRUE,IF(AND"/>

Translating string formula to cell formula in regional language changes relative reference

50 Views Asked by At

I have the following US-English version of the formula pasted in Cell C15 of Sheet TemplateMap as:

'=IF(AND($H11="H",L11>=1,ISNUMBER(L11)),TRUE,IF(AND($H11<>"H",L11>=0,ISNUMBER(L11)),TRUE,FALSE))

Where some columns are absolute and rows relative. This formula is to be applied in VBA code to a the cells of a Sheet Base_Price.

For a user in Poland, the polish formula would be:

'=IF(AND($H11="H";L11>=1;ISNUMBER(L11));TRUE;IF(AND($H11<>"H";L11>=0;ISNUMBER(L11));TRUE;FALSE))

ISSUE:

  • In the formula, the "," commas do not get translated to ";" semicolons for Poland.
  • Also, the .RefersToLocal gives incorrect Column and Row references (unless I make Absolute all the rows and columns in the original formula).
  • Active Sheet name gets added to the formula in .RefersToLocal.

Here is what I tried:

Sub Tester()
    Dim V As Variant
    
    V = FormulaToLocal(ThisWorkbook.Worksheets("TemplateMap").Range("C15"))
    Debug.Print V
End Sub

Function FormulaToLocal(ByRef rCell As Range) As Variant
    Dim x As Variant
    
    ThisWorkbook.Names.Add "myFormula", RefersTo:=rCell.Formula
    FormulaToLocal = ThisWorkbook.Names("myFormula").RefersToLocal
    
    ThisWorkbook.Names("myFormula").Delete
End Function

the output that i am getting if i activate Base_Price sheet:

=IF(AND(Base_Price!$H16="H";Base_Price!U16>=1;ISNUMBER(Base_Price!U16));TRUE;IF(AND(Base_Price!$H16<>"H";Base_Price!U16>=0;ISNUMBER(Base_Price!U16));TRUE;FALSE))

the output that i am getting if i activate TemplateMap sheet:

=IF(AND(TemplateMap!$H25="H";TemplateMap!M25>=1;ISNUMBER(TemplateMap!M25));TRUE;IF(AND(TemplateMap!$H25<>"H";TemplateMap!M25>=0;ISNUMBER(TemplateMap!M25));TRUE;FALSE))

The expected output should be as shown below without activating any sheets or adding sheet name to original formula:

'=IF(AND($H11="H";L11>=1;ISNUMBER(L11));TRUE;IF(AND($H11<>"H";L11>=0;ISNUMBER(L11));TRUE;FALSE))```
0

There are 0 best solutions below