I'm trying to create an international Excel macro sheet.
These macros should work for many countries
I'm writing formulas in English using Range.formula, but it does not work for all formulas (?)
For example, I create
Range("D4").Formula = "=SUM(D7:D14)"
In Spanish Excel it works so is filled with "=SUMA(D7:D14)". Is correct
Other formulas fails, for example:
"=IF(R2=8;D7;D6)" 'In Spanish Excel I get error 1004
"=ISNUMBER(O2)" works =ESNUMERO(O2)
"=PRODUCT(O2;O3)" Does not work, error 1004
I'm with Excel 2010 and Windows 7 , and I cannot understand this strange behavior. Parameters are valid for all formulas
Any ideas?
Range.Formula expects English formula notation. This means not only English function names but also using comma to separate parameters and not semicolon.
So
...Formula = "=IF(R2=8,D7,D6)"
and
...Formula = "=PRODUCT(O2,O3)"
should work.
Related
When a user manually enters formula in a sheet in the English version of Excel and sends this document to another user who has Excel in another version, the formula is automatically translated to the language in which the document is opened.
'Formula entered in Sheet1!B1 in the English Excel version
=VLOOKUP(A1,Sheet2!$A$1:$C$150,3,FALSE)
'Formula as shown in a Dutch Excel version
=VERT.ZOEKEN(A1;Sheet2!$A$1:$C$150;3;ONWAAR)
When I programmatically add a formula, in my English version, it would look like this:
Sub AddFormula()
ThisWorkbook.Worksheets("Sheet1").Cells(1, 2).Formula = "=VLOOKUP(A1,Sheet2!$A$1:$C$150,3,FALSE)"
End Sub
If I were to run this procedure on my English Version, then save the document and send it over to a user with another language, it would be fine as the formula is in the cell and thus translated to whatever language and locale the 2nd user uses.
My question is what happens when the 2nd user runs the procedure, in the Dutch (or other language for that matter) Excel with the formula in the code written in the EN-US format. Will it be translated or will it throw an error and in case of the latter, how would I solve that and make the formula insertion language proof?
In Excel vba the .Formula requires that the formula to be inserted be in EN-USA format. This is regardless of the local settings.
Excel will then translate it into the local vernacular when putting it in the sheet.
So no matter what the local settings it will work cross languages.
VBA also has the .FormulaLocal which allows the entry of the formula in the native language. But (as far as I know) it will not work cross different local settings.
I got a report in excel and I'm having some trouble with a Russian PC. The formula TEXT is being used to get the month name from a date but, in the Russian PC it's not working and not given an error.
The formula is =TEXT(D7, "mmm") and the result is "mmm".
I also tried (The excel way to handle dates in different languages):
=TEXT(D7, "[$-409]mmm") and the result is "mmm".
I've tested different date functions and they all working. (Sum(), month(), changing data format, etc).
Version: Excel 365
As it works in my pc, does anyone have any idea what might be causing the error?
First - The mmm should be MMM.
Then, the fact that the PC is in Russian is a bit irrelevant. What matters is the installation language of Excel.
You may try the following
write 43319 on range A1;
then write this formula =TEXT(A1,"MMM"), using the English M and not the Cyrillic ones. Although they look quite the same, they are different.
it should return Aug as the month;
I've found a way to fix it creating a new formula in VBA and it worked great.
Press Alt+F11 (to open the VBA editor) Then Click the menu item Insert > Module In the new VBA module, enter the following:
Public Function FMT$(ByVal Value, ByVal strFormat)
FMT = VBA.Format$(Value, strFormat)
End Function
To use this, simply type =FMT(A1, "MMM") instead of =TEXT(A1, "MMM").
Credits to https://superuser.com/questions/730371/how-to-prevent-excel-to-use-the-os-regional-settings-for-date-patterns-in-formul
When a user manually enters formula in a sheet in the English version of Excel and sends this document to another user who has Excel in another version, the formula is automatically translated to the language in which the document is opened.
'Formula entered in Sheet1!B1 in the English Excel version
=VLOOKUP(A1,Sheet2!$A$1:$C$150,3,FALSE)
'Formula as shown in a Dutch Excel version
=VERT.ZOEKEN(A1;Sheet2!$A$1:$C$150;3;ONWAAR)
When I programmatically add a formula, in my English version, it would look like this:
Sub AddFormula()
ThisWorkbook.Worksheets("Sheet1").Cells(1, 2).Formula = "=VLOOKUP(A1,Sheet2!$A$1:$C$150,3,FALSE)"
End Sub
If I were to run this procedure on my English Version, then save the document and send it over to a user with another language, it would be fine as the formula is in the cell and thus translated to whatever language and locale the 2nd user uses.
My question is what happens when the 2nd user runs the procedure, in the Dutch (or other language for that matter) Excel with the formula in the code written in the EN-US format. Will it be translated or will it throw an error and in case of the latter, how would I solve that and make the formula insertion language proof?
In Excel vba the .Formula requires that the formula to be inserted be in EN-USA format. This is regardless of the local settings.
Excel will then translate it into the local vernacular when putting it in the sheet.
So no matter what the local settings it will work cross languages.
VBA also has the .FormulaLocal which allows the entry of the formula in the native language. But (as far as I know) it will not work cross different local settings.
I am currently rewriting some old Access code that defined named ranges in an excel workbook.
The old code is as follow:
oWorkbook.Names.Add "NameOfRange", "='Sheet1'!$A$1:$L2000"
With oWorkbook a Workbook opened from Access.
Since the range (number of rows) can change, I planned to use dynamic named ranges using Offset and CountA functions, and wrote the following code to replace the previous one:
oWorkbook.Names.Add "NameOfRange", "=OFFSET('Sheet1'!$A$1,0,0,COUNTA('Sheet1'!$A:$A),12)"
but then excel send an error 1004 There is a problem with this formula.
The same line of code executed from an Excel workbook works fine, and give the expected result.
On my computer, I use mixed English/French international settings, and my Office 2016 is in English, so I have a ListSeparator as ;.
When replacing the , by ;, the new formula below works:
oWorkbook.Names.Add "NameOfRange", "=OFFSET('Sheet1'!$A$1;0;0;COUNTA('Sheet1'!$A:$A);12)"
but I need my function to work on every configuration, not on only French/English bizaroid settings.
I tried to specify the named arguments (Name:= ... and RefersTo:=...) but its not correcting the problem. When called from Access, the code still need local separators (and maybe local function names? no idea).
So I can retrieve the computer excel List Separator (Using oWorkbook.Application.International(xlListSeparator) and replace all , in the formula with it, but maybe I am doing something wrongly and there is a better way to do?
I am working on some Excel functionality using VB - but I am getting stuck at some examples.
Current version is Excel 2007, using a blank Workbook; I've added in a module and trying a function like the following:
Function Addtwo(a, b)
Addtwo = a + b
End Function
However, I get the error #VALUE! in my cell, when doing Addtwo(5,5). When trying to do Addtwo(B2,B3), Excel tells me my formula is wrong.
Thanks,
The pasted code is okay and works in my Excel 2007.
The only possible problems I can think of:
You forgot to use the equal sign: Addtwo(5,5) instead of =Addtwo(5,5)
Your language settings require a semicolon instead of a comma in the formula, i.e. =Addtwo(5;5) (in the worksheet formula only, not in the VBA code)