currency conversion:number to words excel - excel-formula
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.
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.
Reading consequent text files by using arrays in VBA
I am trying to write a VBA code to read values and write it to where I want from 4 thousand different text files. As an example the fine name is like NACA63220_1.30_17_CD.txt and NACA63220_1.05_12_CL.txt In this name, the value 1.30 changes, 17 changes and CD becomes CL etc. I want to create loops so that I read and paste the value I want from these files one by one. Mach = Array ("0.2_", "0.6_", "0.9_", "1.05_", "1.30_") Alpha = Array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20) Letter = Array("_CD", "_CL", "_CM") strFile = D:\Database\NACA63220_ + Mach(5) + Alpha(18) + Letter(1) .txt I want to have something like this with loops so that in this instance this strFile becomes D:\Database\NACA63220_ 1.30_17_CD.txt and then I can continue with my code.
You need to concatenate strings with & not + (which is for calculation only). Also your strings need to be enclosed in quotes "". strFile = "D:\Database\NACA63220_" & Mach(5) & Alpha(18) & Letter(1) & ".txt" Note that depending on how your arrays were defined the counting starts with zero 0 not with 1. So the last item is Mach(4) not Mach(5). In this case … strFile = "D:\Database\NACA63220_" & Mach(4) & Alpha(17) & Letter(0) & ".txt" should give the desired result D:\Database\NACA63220_ 1.30_17_CD.txt
How to substitute multiple line feed with a single line feed
I have this data in a single cell wrapped. This is a bad dream For my report formatting purpose, i need to reduce multiple line feeds. Whenever there are more than 2 line feeds between 2 strings, they need to be replaced by exactly 2 line feed. So the data must look like This is a bad dream I'm just a beginner in excel scripting. I tried using the substitute function but couldn't get the right result. Can some looping be done using substitute?
Whenever there are more than 2 line feeds between 2 strings, they need to be replaced by exactly 2 line feed. Use this small function: Function customSubstitute(myStr As String) As String customSubstitute = myStr Do While InStr(1, customSubstitute, Chr(10) & Chr(10) & Chr(10)) customSubstitute = Replace(customSubstitute, Chr(10) & Chr(10) & Chr(10), Chr(10) & Chr(10)) Loop End Function
Excel Amount in Words 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
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")