Call 0700ANALYTICS, +234-808-938-2423, +1-941-312-2149 or Mail: info@UrBizEdge.com or Visit: www.urbizedge.com | Privacy Policy | Terms and Conditions

# Register for the next special Business Data Analysis and In-depth Excel Training

## Monday, July 22, 2019

### How To Create Formula (UDF) That Converts Number or Money Amounts to Words in Naira and Kobo or Dollars and Cents

The first time I was asked a question around this was in 2016 at a training I had for eHealth Africa in Kano. A couple of the finance managers wanted to be able to convert money amounts to words with Naira and kobo in appropriate places.

Then two weeks ago in Abuja, I got asked the same question by finance team at HSDF and it became obvious to me that it is a problem many people would like easy steps to accomplishing. Many people who come across solutions online still face roadblocks in implementing the solution satisfactorily.

Well, as a patriotic Nigerian, I have come in my shining armor to give every Nigerian an almost plug and play solution with easy to understand steps.

Solution (Warri style)

Then go to File, Options, Add-ins and click on Go in front of Manage Excel Add-ins.

Click on browse to pick the files (one at a time).

Ensure they are ticked as part of enabled/available add-ins.

And that's all! Now, go and type less henceforth.

Explanation (Brother Jero style)
What we are trying to achieve is a simple task called User Defined Function -- creating our own formulas that the Engineers at Microsoft didn't include in Excel. Unfortunately, the process is not straightforward. We would have to not get on the wrong side of Amope (VBA).

We would use a modified version of this boilerplate from Microsoft with some extra tweaks from Ablebits.

Here's the one for Naira and Kobo:

Option Explicit
'Main Function
Function SpellNumberNGN(ByVal MyNumber)
Dim Naira, Kobo, Temp
Dim DecimalPlace, Count
ReDim Place(9) As String
Place(2) = " Thousand "
Place(3) = " Million "
Place(4) = " Billion "
Place(5) = " Trillion "

MyNumber = Trim(Str(MyNumber))
DecimalPlace = InStr(MyNumber, ".")
If DecimalPlace &gt; 0 Then
Kobo = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) &amp; _
"00", 2))
MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
End If
Count = 1
Do While MyNumber &lt;&gt; ""
Temp = GetHundreds(Right(MyNumber, 3))
If Temp &lt;&gt; "" Then Naira = Temp &amp; Place(Count) &amp; Naira
If Len(MyNumber) &gt; 3 Then
MyNumber = Left(MyNumber, Len(MyNumber) - 3)
Else
MyNumber = ""
End If
Count = Count + 1
Loop
Select Case Naira
Case ""
Naira = ""
Case "One"
Naira = "One Naira"
Case Else
Naira = Naira &amp; " Naira"
End Select
Select Case Kobo
Case ""
Kobo = ""
Case "One"
Kobo = " and One Kobo"
Case Else
Kobo = " and " &amp; Kobo &amp; " Kobo"
End Select
SpellNumberNGN = Naira &amp; Kobo
End Function

Function GetHundreds(ByVal MyNumber)
Dim Result As String
If Val(MyNumber) = 0 Then Exit Function
MyNumber = Right("000" &amp; MyNumber, 3)
' Convert the hundreds place.
If Mid(MyNumber, 1, 1) &lt;&gt; "0" Then
Result = GetDigit(Mid(MyNumber, 1, 1)) &amp; " Hundred "
End If
' Convert the tens and ones place.
If Mid(MyNumber, 2, 1) &lt;&gt; "0" Then
Result = Result &amp; GetTens(Mid(MyNumber, 2))
Else
Result = Result &amp; GetDigit(Mid(MyNumber, 3))
End If
GetHundreds = Result
End Function

Function GetTens(TensText)
Dim Result As String
Result = "" ' Null out the temporary function value.
If Val(Left(TensText, 1)) = 1 Then   ' If value between 10-19...
Select Case Val(TensText)
Case 10: Result = "Ten"
Case 11: Result = "Eleven"
Case 12: Result = "Twelve"
Case 13: Result = "Thirteen"
Case 14: Result = "Fourteen"
Case 15: Result = "Fifteen"
Case 16: Result = "Sixteen"
Case 17: Result = "Seventeen"
Case 18: Result = "Eighteen"
Case 19: Result = "Nineteen"
Case Else
End Select
Else ' If value between 20-99...
Select Case Val(Left(TensText, 1))
Case 2: Result = "Twenty "
Case 3: Result = "Thirty "
Case 4: Result = "Forty "
Case 5: Result = "Fifty "
Case 6: Result = "Sixty "
Case 7: Result = "Seventy "
Case 8: Result = "Eighty "
Case 9: Result = "Ninety "
Case Else
End Select
Result = Result &amp; GetDigit _
(Right(TensText, 1))  ' Retrieve ones place.
End If
GetTens = Result
End Function

Function GetDigit(Digit)
Select Case Val(Digit)
Case 1: GetDigit = "One"
Case 2: GetDigit = "Two"
Case 3: GetDigit = "Three"
Case 4: GetDigit = "Four"
Case 5: GetDigit = "Five"
Case 6: GetDigit = "Six"
Case 7: GetDigit = "Seven"
Case 8: GetDigit = "Eight"
Case 9: GetDigit = "Nine"
Case Else: GetDigit = ""
End Select
End Function

You will copy this. Open an empty/new Excel file, press Alt + F11. The VBA Editor will open. On the menu, select Insert and click on Module. Then paste the code above in it.

Save (CTRL + S), but choose Excel Add-in as the save as type. Importantly, do not change the default folder Excel will automatically change to for saving for the file. If you do this, then you are OYO.

Now we are almost there.

Repeat same steps for dollar and cents (if you need it). Here is the code for that:

Option Explicit
'Main Function
Function SpellNumberUSD(ByVal MyNumber)
Dim Dollars, Cents, Temp
Dim DecimalPlace, Count
ReDim Place(9) As String
Place(2) = " Thousand "
Place(3) = " Million "
Place(4) = " Billion "
Place(5) = " Trillion "

MyNumber = Trim(Str(MyNumber))
DecimalPlace = InStr(MyNumber, ".")
If DecimalPlace &gt; 0 Then
Cents = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) &amp; _
"00", 2))
MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
End If
Count = 1
Do While MyNumber &lt;&gt; ""
Temp = GetHundreds(Right(MyNumber, 3))
If Temp &lt;&gt; "" Then Dollars = Temp &amp; Place(Count) &amp; Dollars
If Len(MyNumber) &gt; 3 Then
MyNumber = Left(MyNumber, Len(MyNumber) - 3)
Else
MyNumber = ""
End If
Count = Count + 1
Loop
Select Case Dollars
Case ""
Dollars = "No Dollars"
Case "One"
Dollars = "One Dollar"
Case Else
Dollars = Dollars &amp; " Dollars"
End Select
Select Case Cents
Case ""
Cents = ""
Case "One"
Cents = " and One Cent"
Case Else
Cents = " and " &amp; Cents &amp; " Cents"
End Select
SpellNumberUSD = Dollars &amp; Cents
End Function

Function GetHundreds(ByVal MyNumber)
Dim Result As String
If Val(MyNumber) = 0 Then Exit Function
MyNumber = Right("000" &amp; MyNumber, 3)
' Convert the hundreds place.
If Mid(MyNumber, 1, 1) &lt;&gt; "0" Then
Result = GetDigit(Mid(MyNumber, 1, 1)) &amp; " Hundred "
End If
' Convert the tens and ones place.
If Mid(MyNumber, 2, 1) &lt;&gt; "0" Then
Result = Result &amp; GetTens(Mid(MyNumber, 2))
Else
Result = Result &amp; GetDigit(Mid(MyNumber, 3))
End If
GetHundreds = Result
End Function

Function GetTens(TensText)
Dim Result As String
Result = "" ' Null out the temporary function value.
If Val(Left(TensText, 1)) = 1 Then   ' If value between 10-19...
Select Case Val(TensText)
Case 10: Result = "Ten"
Case 11: Result = "Eleven"
Case 12: Result = "Twelve"
Case 13: Result = "Thirteen"
Case 14: Result = "Fourteen"
Case 15: Result = "Fifteen"
Case 16: Result = "Sixteen"
Case 17: Result = "Seventeen"
Case 18: Result = "Eighteen"
Case 19: Result = "Nineteen"
Case Else
End Select
Else ' If value between 20-99...
Select Case Val(Left(TensText, 1))
Case 2: Result = "Twenty "
Case 3: Result = "Thirty "
Case 4: Result = "Forty "
Case 5: Result = "Fifty "
Case 6: Result = "Sixty "
Case 7: Result = "Seventy "
Case 8: Result = "Eighty "
Case 9: Result = "Ninety "
Case Else
End Select
Result = Result &amp; GetDigit _
(Right(TensText, 1))  ' Retrieve ones place.
End If
GetTens = Result
End Function

Function GetDigit(Digit)
Select Case Val(Digit)
Case 1: GetDigit = "One"
Case 2: GetDigit = "Two"
Case 3: GetDigit = "Three"
Case 4: GetDigit = "Four"
Case 5: GetDigit = "Five"
Case 6: GetDigit = "Six"
Case 7: GetDigit = "Seven"
Case 8: GetDigit = "Eight"
Case 9: GetDigit = "Nine"
Case Else: GetDigit = ""
End Select
End Function

And now you do the steps I put under the solution section, except that you'll see the add-ins there without needing to browse to them. Ensure they are ticked.

And from now on, you'll have the two formulas that can convert numbers to words (naira/kobo and dollars/cents).

Again, I say to you: enjoy!

1. I need to communicate my deference of your composing aptitude and capacity to make perusers read from the earliest starting point as far as possible. I might want to peruse more up to date presents and on share my musings with you.
360DigiTMG Data Analytics Course

2. Happy to visit your blog, I am by all accounts forward to more solid articles and I figure we as a whole wish to thank such huge numbers of good articles, blog to impart to us.
https://360digitmg.com/course/certification-program-in-data-science

3. I think I have never watched such online diaries ever that has absolute things with all nuances which I need. So thoughtfully update this ever for us.
difference between analysis and analytics

4. I looked at some very important and to maintain the length of the strength you are looking for on your website
iot training in noida

5. I need to communicate my deference of your composing aptitude and capacity to make perusers read from the earliest starting point as far as possible. I might want to peruse more up to date presents and on share my musings with you.
https://360digitmg.com/course/artificial-intelligence-ai-and-deep-learning

6. Extremely overall quite fascinating post. I was searching for this sort of data and delighted in perusing this one. Continue posting. A debt of gratitude is in order for sharing.Best data analytics course in Hyderabad

7. Regular visits listed here are the easiest method to appreciate your energy, which is why why I am going to the website everyday, searching for new, interesting info. Many, thank you!
Best Institute for Data Science in Hyderabad

8. Excellent blog with valuable information and just added your blog to my bookmarking sites thank for sharing.
Data Science Course in Bangalore

9. Really I enjoy your site with effective and useful information. It is included very nice post with a lot of our resources.thanks for share. i enjoy this post. Mason Jacob

10. I feel very grateful that I read this. It is very helpful and very informative and I really learned a lot from it.
Data Analytics Course

11. I am really enjoying reading your well written articles. I am looking forward to reading new articles. Keep up the good work.
Data Science Courses in Bangalore

12. What an incredible message this is. Truly one of the best posts I have ever seen in my life. Wow, keep it up.
AI Courses in Bangalore

13. I am sure it will help many people. Keep up the good work. It's very compelling and I enjoyed browsing the entire blog.

14. This post is very simple to read and appreciate without leaving any details out. Great work!

15. Excellent effort to make this blog more wonderful and informative. The information shared was very useful.
Data Analytics Course in Chandigarh

16. Very nice job... Thanks for sharing this amazing and educative blog post!
Data Science Course in Chandigarh

17. Amazingly by and large very interesting post. I was looking for such an information and thoroughly enjoyed examining this one. Keep posting.
An obligation of appreciation is all together for sharing.data analytics course in gwalior

18. Very nice job... Thanks for sharing this amazing and educative blog post!
Data Science Training in Lucknow

19. It's late discovering this demonstration. At any rate, it's a thing to be acquainted with that there are such occasions exist. I concur with your Blog and I will have returned to investigate it more later on so please keep up your demonstration.https://360digitmg.com/course/data-analytics-using-python-r

20. A good blog always contains new and exciting information and as I read it I felt that this blog really has all of these qualities that make a blog.
Data Science Institutes in Bangalore