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!