Excel Amount in Words Formula - excel-formula

I found this formula below to convert amounts to words for google spreadsheets and it works perfectly. But now I want to use it in excel 2010 and I get a lot of errors. I also cannot use VBA. Thanks for any help.
=if(or(isBlank(A1),not(isNumber(A1)),A1>=power(10,15)),ifError(1/0,"Error"),trim(arrayFormula(concatenate(if(trunc(mod(A1,power(10,{15,12,9,6,3}))/power(10,{12,9,6,3,0}))<100,"",choose(int(trunc(mod(A1,power(10,{15,12,9,6,3}))/power(10,{12,9,6,3,0}))/100)," One"," Two"," Three"," Four"," Five"," Six"," Seven"," Eight"," Nine") & " Hundred") & if(mod(trunc(mod(A1,power(10,{15,12,9,6,3}))/power(10,{12,9,6,3,0})),100)<>0,if(trunc(mod(A1,power(10,{15,12,9,6,3}))/power(10,{12,9,6,3,0}))>100," And",if(A1>power(10,{15,12,9,6,3}),choose({1,2,3,4,5},"","","",""," And"),"")),"") & if(mod(trunc(mod(A1,power(10,{15,12,9,6,3}))/power(10,{12,9,6,3,0})),100)=0,"",if(mod(trunc(mod(A1,power(10,{15,12,9,6,3}))/power(10,{12,9,6,3,0})),100)<20,choose(mod(trunc(mod(A1,power(10,{15,12,9,6,3}))/power(10,{12,9,6,3,0})),100)," One"," Two"," Three"," Four"," Five"," Six"," Seven"," Eight"," Nine"," Ten"," Eleven"," Twelve"," Thirteen"," Fourteen"," Fifteen"," Sixteen"," Seventeen"," Eighteen"," Nineteen"),choose(int(mod(trunc(mod(A1,power(10,{15,12,9,6,3}))/power(10,{12,9,6,3,0})),100)/10),""," Twenty"," Thirty"," Forty"," Fifty"," Sixty"," Seventy"," Eighty"," Ninety") & if(mod(mod(trunc(mod(A1,power(10,{15,12,9,6,3}))/power(10,{12,9,6,3,0})),100),10)=0,"","-" & choose(mod(mod(trunc(mod(A1,power(10,{15,12,9,6,3}))/power(10,{12,9,6,3,0})),100),10),"One","Two","Three","Four","Five","Six","Seven","Eight","Nine")))) & if(trunc(mod(A1,power(10,{15,12,9,6,3}))/power(10,{12,9,6,3,0}))=0,"",choose({1,2,3,4,5}," Trillion"," Billion"," Million"," Thousand","")))) & if(A1>=2," Rand",if(A1>=1," Rand","")) & if((round(A1-trunc(A1),2)*100=0)+(A1<1),""," And") & if(round(A1-trunc(A1),2)*100=0,"",if(round(A1-trunc(A1),2)*100=1," One Cent",if(round(A1-trunc(A1),2)*100<20,choose(round(A1-trunc(A1),2)*100," One"," Two"," Three"," Four"," Five"," Six"," Seven"," Eight"," Nine"," Ten"," Eleven"," Twelve"," Thirteen"," Fourteen"," Fifteen"," Sixteen"," Seventeen"," Eighteen"," Nineteen"),choose(int(round(A1-trunc(A1),2)*100/10),""," Twenty"," Thirty"," Forty"," Fifty"," Sixty"," Seventy"," Eighty"," Ninety") & if(mod(round(A1-trunc(A1),2)*100,10)=0,"","-" & choose(mod(round(A1-trunc(A1),2)*100,10),"One","Two","Three","Four","Five","Six","Seven","Eight","Nine"))) & " Cent"))))

If your numbers do not need to go above ~100, it may be easier to make two columns, the first with the 1,2,3 etc. and the second with one,two,three etc. Then you can do VLOOKUP() on that table.
An example can be found here: https://www.dropbox.com/s/e44dnkg3he8b8il/NumericalToAlpha.xlsx

Related

Excel VBA adding table to Pivot Table Data model

Good day,
I'm trying to insert a pivot table from a table but also add it to a data model via VBA.
I've recorded the process manually and also followed the example of this link: https://powerpivotpro.com/2014/07/adding-tables-to-a-model-from-vba-in-excel-2013/
I change the variables for my data path and workbook name that has been set previously in the code. When I run the macro I get the following error on the first line: "Run-Time error 5: Invalid procedure call or argument".
I've never added a pivot table to a data model via VBA before, thus not sure how the code should look (except what I've seen online and mine seem to adhere to the example)
MainWB.Connections.Add2 "WorksheetConnection_" & MainWB.Name & "!Table_SDCdata", "", _
"WORKSHEET;" & DataPath & "\" & MainWB.Name & ", " & MainWB.Name & "!Table_SDCdata", 7, True, False
MainWB.PivotCaches.Create(SourceType:=xlExternal, SourceData:=MainWB.Connections("WorksheetConnection_" & MainWB.Name & "!Table_SDCdata" _
), Version:=6).CreatePivotTable TableDestination:=wsPivotModel.Name & "!R1C1", TableName:="PvtSDCmodel", DefaultVersion:=6
The variables are as follows: (** added to replace for security in this question, both variables are correct and used many times in the code without problems)
MainWB.name: **2791 SDC Inland 12.08.2020.xlsbCOMBINED.xls
DataPath: C:_Store\Simone_d_drive\Desktop*\2019\Macros*\raw data**\2791\2020.08.16
Any help or point in the right direction will be great thank you!
I managed to find my errors:
Updated code:
MainWB.Connections.Add2 "WorksheetConnection_" & MainWB.Name & "!Table_SDCdata", "", _
"WORKSHEET;" & DataPath & "\" & MainWB.Name, MainWB.Name & "!Table_SDCdata", 7, True, False
I had to remove 2 of the quotation marks, one at the end of the connection string and the 2nd one at the beginning of the command text.

Table labeling and referencing in Rmarkdown

I'm using markdown to render in PDF format.
I am able to cross-reference plot, but when I build a table in LaTeX, I can't do it somehow. An example:
We plot in Figure \#ref(fig:plotseries) the three Index series and their log return series. In Table \#ref(tab:summindex_stargazer) the main characteristics...
while the table has been coded as follow:
\begin{table}[!htbp] \centering
\caption[Summary statistics for token indexes under study.]{Summary statistics for large cap (L.MWI), medium cap (M.MWI), and small cap (S.MWI) indexes log return series. \label{tab:summindex_stargazer}}
\footnotesize
\begin{tabular}{#{\extracolsep{5pt}} cccc}
\\[-1.8ex]\hline
\hline \\[-1.8ex]
& L.MWI Returns & M.MWI Returns & S.MWI Returns \\
\hline \\[-1.8ex]
nobs & $1,524$ & $1,380$ & $1,362$ \\
NAs & $0$ & $0$ & $0$ \\
Minimum & $-0.351$ & $-0.549$ & $-0.933$ \\
Maximum & $0.464$ & $0.699$ & $1.010$ \\
1. Quartile & $-0.031$ & $-0.034$ & $-0.052$ \\
3. Quartile & $0.036$ & $0.039$ & $0.050$ \\
Mean & $0.003$ & $0.004$ & $0.002$ \\
Median & $0.002$ & $0.004$ & $-0.003$ \\
Sum & $4.144$ & $5.333$ & $2.863$ \\
SE Mean & $0.002$ & $0.002$ & $0.004$ \\
LCL Mean & $-0.001$ & $0.000$ & $-0.005$ \\
UCL Mean & $0.006$ & $0.008$ & $0.009$ \\
Variance & $0.004$ & $0.005$ & $0.017$ \\
Stdev & $0.066$ & $0.073$ & $0.130$ \\
Skewness & $0.236$ & $0.214$ & $1.000$ \\
Kurtosis & $4.355$ & $11.602$ & $13.393$ \\
\hline \\[-1.8ex]
\end{tabular}
\end{table}
This is the result.
Found out the solution. Basically you are not allowed to use “underscore”(_) in table labels.
It was so simple but also so incredibly hard to find out (I personally know many people who’d encountered this error and were not able to solve it). I hope it will help.
Adding to what is written here, underscores are one of 10 special characters in LaTeX.
For underscores to be permitted in table labels they need to be escaped.
This should work:
\#ref(tab:summindex\_stargazer)
But not this:
\#ref(tab:summindex_stargazer)
See this discussion for an excellent reference on special characters.

If cell is blank, what to do?

I have line of code in excel and would like to add a function that If reference cell is empty, just return me empty. How am I able to add to that? Thanks in advance!
Here My code is so far:
=IF(
ISNA(VLOOKUP($A2,'[DataSheet.xlsx]SOC 41'!$C$2:$P$5000,1,FALSE))=TRUE,"","R41: " & VLOOKUP($A2,'[DataSheet.xlsx]SOC 41'!$C$2:$P$5000,10,FALSE))&"
"&IF(ISNA(VLOOKUP($A2,'[DataSheet.xlsx]SOC 42'!$C$2:$P$5000,1,FALSE))=TRUE,"","R42: " & VLOOKUP($A2,'[DataSheet.xlsx]SOC 42'!$C$2:$P$5000,10,FALSE))&"
"&IF(ISNA(VLOOKUP($A2,'[DataSheet.xlsx]SOC 43'!$C$2:$P$5000,1,FALSE))=TRUE,"","R43: " & VLOOKUP($A2,'[DataSheet.xlsx]SOC 43'!$C$2:$P$5000,10,FALSE))
Again, what if return cell got an empty string, how to add ISBLANK (or something else) in to the code?
Even I tried this and didn't work.
=IF(OR(
VLOOKUP($A11,'[DataSheet]SOC 41'!$C$2:$P$5000,11,FALSE)="",
VLOOKUP($A11,'[DataSheet]SOC 42'!$C$2:$P$5000,11,FALSE)="",
VLOOKUP($A11,'[DataSheet]SOC 43'!$C$2:$P$5000,11,FALSE)=""),"",
IF(
ISNA(VLOOKUP($A11,'[DataSheet]SOC 41'!$C$2:$P$5000,1,FALSE))=TRUE,"","R41: " & VLOOKUP($A11,'[DataSheet]SOC 41'!$C$2:$P$5000,11,FALSE))&"
"&IF(ISNA(VLOOKUP($A11,'[DataSheet]SOC 42'!$C$2:$P$5000,1,FALSE))=TRUE,"","R42: " & VLOOKUP($A11,'[DataSheet]SOC 42'!$C$2:$P$5000,11,FALSE))&"
"&IF(ISNA(VLOOKUP($A11,'[DataSheet]SOC 43'!$C$2:$P$5000,1,FALSE))=TRUE,"","R43: " & VLOOKUP($A11,'[DataSheet]SOC 43'!$C$2:$P$5000,11,FALSE)))
Please help!
Nest the formula in:
=if(A2<>"",formula,"")

currency conversion:number to words excel

I would like to convert the the Kuwait currency which has three decimal places into words in an Excel Document.The formula i used is as follows:
=if(or(isBlank($E$89),not(isNumber($E$89)),$E$89>=power(10,15)),ifError(1/0),trim(arrayFormula(concatenate(if(trunc(mod($E$89,power(10,15,12,9,6,3}))/power(10,{12,9,6,3,0}))<100,"",switch(int(trunc(mod($E$89,power(10,{15,12,9,6,3}))/power(10,{12,9,6,3,0}))/100),1," one",2," two",3," three",4," four",5," five",6," six",7," seven",8," eight",9," nine") & " hundred") & if(mod(trunc(mod($E$89,power(10,{15,12,9,6,3}))/power(10,{12,9,6,3,0})),100)<>0,if(trunc(mod($E$89,power(10,{15,12,9,6,3}))/power(10,{12,9,6,3,0}))>100," and",if($E$89>power(10,{15,12,9,6,3}),switch({1,2,3,4,5},5," and"),"")),"") & if(mod(trunc(mod($E$89,power(10,{15,12,9,6,3}))/power(10,12,9,6,3,0})),100)=0,"",if(mod(trunc(mod($E$89,power(10,{15,12,9,6,3}))/power(10,{12,9,6,3,0})),100)<20,IFERROR(switch(mod(trunc(mod($E$89,power(10,{15,12,9,6,3}))/power(10,{12,9,6,3,0})),100),1," one",2," two",3," three",4," four",5," five",6," six",7," seven",8," eight",9," nine",10," ten",11," eleven",12," twelve",13," thirteen",14," fourteen",15," fifteen",16," sixteen",17," seventeen",18," eighteen",19," nineteen")),IFERROR(switch(int(mod(trunc(mod($E$89,power(10,{15,12,9,6,3}))/power(10,{12,9,6,3,0})),100)/10),2," twenty",3," thirty",4," forty",5," fifty",6," sixty",7," seventy",8," eighty",9," ninety")) & if(mod(mod(trunc(mod($E$89,power(10,{15,12,9,6,3}))/power(10,12,9,6,3,0})),100),10)=0,"","-" & IFERROR(switch(mod(mod(trunc(mod($E$89,power(10,{15,12,9,6,3}))/power(10,{12,9,6,3,0})),100),10),1,"one",2,"two",3,"three",4,"four",5,"five",6,"six",7,"seven",8,"eight",9,"nine"))))) & if(trunc(mod($E$89,power(10,{15,12,9,6,3}))/power(10,{12,9,6,3,0}))=0,"",IFERROR(switch({1,2,3,4,5},1," trillion",2," billion",3," million",4," thousand"))))) & if($E$89>=2," Dinar only",if($E$89>=1," Dinar only","")) & if((round($E$89-trunc($E$89),3)*1000=0)+($E$89<1),""," and") & switch(trunc(round($E$89-trunc($E$89),3)*1000,-2)/100,1," one-hundred",2," two",3,-hundred" three-hundred",4," four-hundred",5," five-hundred",6," six-hundred",7," seven-hundred",8," eight-hundred",9," nine-hundred"& if(round($E$89-trunc($E$89),3)*1000-trunc(round($E$89-trunc($E$89),3)*1000,-2)<20,switch(round($E$89-trunc($E$89),3)*1000-trunc(round($E$89-trunc($E$89),3)*1000,-1),0,"",1," one",2," two",3," three",4," four",5," five",6," six",7," seven",8," eight",9," nine",10," ten",11," eleven",12," twelve",13," thirteen",14," fourteen",15," fifteen",16," sixteen",17," seventeen",18," eighteen",19," nineteen"),switch((round($E$89-trunc($E$89),3)*1000-trunc(round($E$89-trunc($E$89),3)*1000,-2))/10,2," twenty",3," thirty",4," forty",5," fifty",6," sixty",7," seventy",8," eighty",9," ninety") & if(mod(round($E$89-trunc($E$89),3)*1000,10)=0,"","-" & switch(round($E$89-trunc($E$89),3)*1000-trunc(round($E$89-trunc($E$89),3)*1000,-1),0"",1,"one",2,"two",3,"three",4,"four",5,"five",6,"six",7,"seven",8,"eight",9,"nine"))) & " fils only")))
The error shown is
Formula parse error
For a given input:
111.250
i would expect to get the output as :
One hundred and eleven Dinar and two hundred fifty fils only.
Try looking for JavaScript solutions to use then as custom function.
I've found is this code, provided by #Vilas Shetkar:
https://stackoverflow.com/a/37409158/5372400
I've tested this code and it works in sheets, so you may adopt this or other similar solutions to your needs.

how do I format currency inside the expression of Excel cell?

I am trying to figure out how to format the result in an expression in Excel. I wrote
=IF(C30 > B30, "You would save $" & Format(C30-B30, "Currency") & "!", "No savings")
inside the cell but it doesn't work. Simply put, I want the currency formatted inside the expression.
How?
Have you tried the Text function?
=IF(C30 > B30, "You would save " & Text(C30-B30, "$0.00") & "!", "No savings")
Use this formula
=IF(C30 > B30, "You would save " & Currency(C30-B30, 0) & "!", "No savings")
Many years later, this works, too!
=IF(C4>D4,"You would save " & DOLLAR(C4-D4,2) & "!","No Savings!")
I think you are looking for the Concatenate function. Excel doesn't seem to have the Format function you have indicated.
This worked for me in Excel 2007:
=IF(C30 > B30, CONCATENATE("You would save $",C30-B30, "!"), "No savings")

Resources