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
Showing posts with label excel. Show all posts
Showing posts with label excel. Show all posts
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)
Download these two Excel files that I saved as add-in files: https://urbizedge.blob.core.windows.net/urbizedge/Numbers2Words.xlam and https://urbizedge.blob.core.windows.net/urbizedge/Numbers2WordsUSD.xlam
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 > 0 Then
Kobo = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & _
"00", 2))
MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
End If
Count = 1
Do While MyNumber <> ""
Temp = GetHundreds(Right(MyNumber, 3))
If Temp <> "" Then Naira = Temp & Place(Count) & Naira
If Len(MyNumber) > 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 & " Naira"
End Select
Select Case Kobo
Case ""
Kobo = ""
Case "One"
Kobo = " and One Kobo"
Case Else
Kobo = " and " & Kobo & " Kobo"
End Select
SpellNumberNGN = Naira & Kobo
End Function
Function GetHundreds(ByVal MyNumber)
Dim Result As String
If Val(MyNumber) = 0 Then Exit Function
MyNumber = Right("000" & MyNumber, 3)
' Convert the hundreds place.
If Mid(MyNumber, 1, 1) <> "0" Then
Result = GetDigit(Mid(MyNumber, 1, 1)) & " Hundred "
End If
' Convert the tens and ones place.
If Mid(MyNumber, 2, 1) <> "0" Then
Result = Result & GetTens(Mid(MyNumber, 2))
Else
Result = Result & 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 & 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 > 0 Then
Cents = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & _
"00", 2))
MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
End If
Count = 1
Do While MyNumber <> ""
Temp = GetHundreds(Right(MyNumber, 3))
If Temp <> "" Then Dollars = Temp & Place(Count) & Dollars
If Len(MyNumber) > 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 & " Dollars"
End Select
Select Case Cents
Case ""
Cents = ""
Case "One"
Cents = " and One Cent"
Case Else
Cents = " and " & Cents & " Cents"
End Select
SpellNumberUSD = Dollars & Cents
End Function
Function GetHundreds(ByVal MyNumber)
Dim Result As String
If Val(MyNumber) = 0 Then Exit Function
MyNumber = Right("000" & MyNumber, 3)
' Convert the hundreds place.
If Mid(MyNumber, 1, 1) <> "0" Then
Result = GetDigit(Mid(MyNumber, 1, 1)) & " Hundred "
End If
' Convert the tens and ones place.
If Mid(MyNumber, 2, 1) <> "0" Then
Result = Result & GetTens(Mid(MyNumber, 2))
Else
Result = Result & 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 & 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!
Wednesday, May 15, 2019
How To Automatically Pull In New Report Data Into Excel Using PowerQuery
One common situation most users of Excel face in making recurrent reports -- daily reports, weekly reports, monthly reports etc -- is that of updating the raw data part of the report with the new data for the period they are creating report for.
As simple as this looks, it is often a boring, repetitive and time consuming task. It could mean having to copy and paste data from the new source data files every day. For some people who get data from different sources (branches, sales people, departments etc), that coping and pasting can easily become a 20 mins task with potentials for human errors.
How do you set up your report to automatically pull in new data from source files? PowerQuery is the answer.
And if you are wondering if this will work for data that you get over emails daily/weekly/monthly. Yes, it works for them too.
The major step is to always save the source files in a dedicated folder. Have a folder on your computer than will hold only those source data files. The files can be Excel files or text files (CSV, TSV etc).
Also, ensure that the files have same table column structure -- same table headers arranged in a consistent manner.
With all these done, you are half way.
In demonstrating this, I have a folder where I put in sales data from different branches of a Pizza restaurant. Everyday, I am required to do sales reports, trend analysis and target/KPI dashboards from all these sales data for management. Before, I would copy paste all the source data in a particular sheet on my daily report template. This could take between 5 to 15 mins depending on how tired/refreshed I was and if any interruption that makes me forget where I stopped.
Now with PowerQuery, all those boring aspect of the reports are fully automated away.
Instead of copying and pasting the content of the different source files into Excel, I go to Data menu, Get & Transform, Get Data, From File and From Folder.
Browse to the folder destination and select it.
You'll see all the files in the folder. Select Combine and Load, in the Combine options.
Pick the sheet that's got the data. That sheet name must be consistent across all the source data files.
Wait a couple of seconds while PowerQuery does its magic.
Notice how all the branches data have been pulled in.
And that's not the best part. The whole essence of my proposing PowerQuery is to handle tomorrow's source data and the days after.
So how does it work?
Very easy.
Just replaced the data files in the folder with tomorrow's data files. Then right click anywhere in the combined table data and select Refresh.
What if there's a new branch that just sent me their data after I had done all of these, what should I do to bring in that new branch's data?
Again, very easy.
Include/save the new branch's data file in the dedicated folder. And click on Refresh in the combined table.
See an example below.
We launched a new branch in Lokoja and after creating my report for the day, I suddenly got an email of the sales data for that branch and asked to include it in the daily report.
I simply add the branch data file to the dedicated folder and click on Refresh in my already existing combined table.
And that's all!
No more zombie-like copying and pasting.
You can watch the short video demonstration: https://youtu.be/mKEHb0OWuP8
Enjoy!
For all your Excel training needs, you can check us out at https://www.urbizedge.com/Excel or call 01-6311885 or email team@urbizedge.com
Monday, August 20, 2018
Industry First (from UrBizEdge): Data Analysis As A Service. You’ll Love It!
We recently came up with this innovative solution for busy professionals. It is an industry first: DaaS. Data Analysis As A Service. A subscription based service. In fact, I'll share with you the very announcement letter/email I sent out to our customers/leads.
| ||
|
Tuesday, July 31, 2018
Join Us: Nigerian Excel Users 2018 Meetup on 1st September, 2018
Last year, we had a great time rubbing minds on the amazing things one could do with Microsoft Excel and had a presentation on other data analytics platforms. There were participants from all over Nigeria and the community has kept growing strong and sharing career growing knowledge.
This year, there will be a similar meetup/conference and you can RSVP at https://www.meetup.com/Nigerian-Excel-Users-Meetup/events/253308965/
Below is the agenda:
Nigerian Excel Users 2018 Meetup
The Zone Tech Park, Plot 9 Gbagada Industrial Scheme, UPS b/stop, Gbagada - Oshodi Expressway, Lagos.
1st September, 2018 (10:00am to 3:30pm)
Start Time: 10:00am
1) Introduction and networking (25 mins)
2) General Discussions pt 1(Your Excel Journey, career advantage, Excel pet peeves, ideas, the esoteric, 40 mins)
3) Presentation 1 (25 mins) + Q & A (10 mins)
4) Presentation 2 (25 mins) + Q & A (10 mins)
5) Break (10 mins)
6) Presentation 3 (25 mins) + Q & A (10 mins)
7) Presentation 4 (25 mins) Q & A (10 mins)
8) Break (10 mins)
9) Presentation 5 (25 mins) Q & A (10 mins)
10) Presentation 6 (25 mins) Q & A (10 mins)
11) General Discussions pt 2 (Your Excel Journey, career advantage, Excel pet peeves, ideas, the esoteric, 30 mins)
12) Close (5 mins)
End Time: 3:30pm (Networking continues)
There will be drinks and snacks.
Also, if you are interested in making a presentation, then you can fill the following Google form (link here)
Monday, July 16, 2018
SUMIF, SUMIFS, COUNTIF and COUNTIFS For Multiple Values of Interest At Once
In case you are not too familiar with SUMIF, SUMIFS, COUNTIF and COUNTIFS, they are a group of formula used to sum or count records that meet a specified criterion.
Below are some easy to follow examples to help you fully grasp them. You can download the practice file here: https://drive.google.com/file/d/15W7zluKlqD3naEyIskvF4xT9wZ22qvYZ/view?usp=sharing
SUMIF
I have a transaction database for a pizza restaurant and I am interested in total sales for Hot Veggie. With SUMIF I can get that done easily.
=SUMIF(B:B,"Hot Veggie",E:E)
Below are some easy to follow examples to help you fully grasp them. You can download the practice file here: https://drive.google.com/file/d/15W7zluKlqD3naEyIskvF4xT9wZ22qvYZ/view?usp=sharing
SUMIF
I have a transaction database for a pizza restaurant and I am interested in total sales for Hot Veggie. With SUMIF I can get that done easily.
=SUMIF(B:B,"Hot Veggie",E:E)
SUMIFS
What if we also want to consider other conditions beyond just the name of the pizza sold, say we want to find the sales amount for all the Hot Veggie sold after 8:30 am?
That is what SUMIFS is for; it is the plural form of SUMIF, allowing you to chain as many conditions as you want.
=SUMIFS(E:E,B:B,"Hot Veggie",F:F,">8:30")
COUNTIF
Maybe I am just interested in the number of transactions that are for Hot Veggie. Again, very easy. We just use COUNTIF.
=COUNTIF(B:B,"Hot Veggie")
COUNTIFS
How about count of transactions for Hot Veggie that happened after 8:30?
=COUNTIFS(B:B,"Hot Veggie",F:F,">8:30")
Now to the very interesting parts. What if I am interested in not just Hot Veggie, but also Meatzaa, Italiano and BBQ Chicken?
Q: Sum all the sales for Meatzaa, Hot Veggie, Italiano and BBQ Chicken
A: =SUM(SUMIF(B:B,{"Meatzaa","Hot Veggie","Italiano","BBQ Chicken"},E:E))
You might wonder why the {..} wrapping the list of pizzas. It is how Excel allows you to specify an array (a list, like we've done). Also, you might wonder why the SUM(...) around the SUMIF formula. It is what allows Excel to sum up all the different answers for each pizza type. See what I mean from the partially calculated formula screenshot below.
And you can use this same pattern for SUMIFS, COUNTIF and COUNTIFS.
Q: Sum all the sales for Meatzaa, Hot Veggie, Italiano and BBQ Chicken after 8:30 am
A: =SUM(SUMIFS(E:E,B:B,{"Meatzaa","Hot Veggie","Italiano","BBQ Chicken"},F:F,">8:30"))
Q: Count of all the transactions for Meatzaa, Hot Veggie, Italiano and BBQ Chicken
A: =SUM(COUNTIF(B:B,{"Meatzaa","Hot Veggie","Italiano","BBQ Chicken"}))
Q: Count of all the transactions for Meatzaa, Hot Veggie, Italiano and BBQ Chicken after 8:30 am
A: =SUM(COUNTIFS(B:B,{"Meatzaa","Hot Veggie","Italiano","BBQ Chicken"},F:F,">8:30"))
For more of these types of very useful tutorials you can check out https://www.urbizedge.com/Tutorials and subscribe to my YouTube channel
Subscribe to:
Posts (Atom)



































