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.

Make us your secret weapon!

Have you ever experienced the analyst's block (kinda like writer's block, when you just don't know how to make the report you want)?

Have you ever felt your report could be better?

Have you ever felt like you were not making the most of the data at your disposal? Like there is more you could be uncovering and tracking and reporting?

Have you ever felt you need experts you can call on any day and at any time but won't cost you an arm and leg?

Okay, maybe I lied about the not costing you an arm and leg. The good thing is that we have structured it flexibly so you can always get more value than the cost.

We have created an industry first: DaaS (Data Analysis as a Service).

Maybe you have tried training. Perhaps you have attended our in-depth high value training class. You have our video learning materials, our book and our practice files. We hope you remember everything we taught you. However, things are changing. You are changing. Your work is changing. The industry is changing. Excel is changing. Power BI is changing. Everything is changing. You already have a demanding job and can't be spending all day keeping abreast of what's new and applicable to you as regards making the most of your data and reports. We are offering to be your secret weapon.

So what's the DaaS structured as?

It is simple and straightforward as ABC.

A. You can reach us remotely (calls, Skype, emails, SMS etc) and at our office (70b Olorunlogbon street, after Banex hotel, Anthony Village, Lagos) for targeted help with your office work. Note: we won't come to your office or house.
B. There is fair usage policy (FUP). So you have to book not less than 24hrs prior and you are entitled to 24hrs/month (which is equivalent to 3 full days) consulting time (both remote and physical). Any length of time above that will attract some extra small charge/fee.
C. You have a dedicated resource (more like technical account manager). It is not Michael. He/she is your primary contact, handles all your work requests, communication, meetings and projects. There is a pool of internal resources (Michael inclusive) he/she will draw on, as appropriate, to satisfy all your relevant needs. We have full-time data analysts that are already handling consulting projects and training, so just as skilled as Michael and they are the ones designated as technical account managers.

So how much does this cost?

That's the best part: there are four flexi plans.
  1. N45,000/month. You can cancel anytime and restart anytime (no refunds, when you cancel it means you just don't pay when your subscription elapses).
  2. N90,000/quarter
  3. N150,000/half-year
  4. N200,000/year
And it's not negotiable. Why that funny pricing structure? That is the result of our own in-house data analytics on the pricing.

We already bill N100,000/day for one-on-one consulting (corporate clients rate is N250,000/day) and even when we are overpowered by the superior negotiating tactics of some of you, we only go as low as N70,000/day for individuals. And that is 8 hrs at a go which is never as effective as two separate 4 hrs, and way less than the 24 hrs spreadable over an entire month that we are offering you at N45,000/month and even less than N19,000/month when you take the year option.

We can only service 10 people at the same time. So if you need our service but delay too much, you will have to wait for an open slot if all 10 slots are taken. And just as we can't review the price downwards, so also will we not accept you doubling the fee so we can take you up.

What do you think?

If interested, get in touch as soon as you can and we will get in touch with you. Reach Michael on 0700ANALYTICS, 0808-938-2423, 0806-312-5227 and mike@urbizedge.com or Hannah on 0802-118-0874 and hannah@urbizedge.com or Emmanuel on 0908-482-5064 and emmanuel@urbizedge.com

Again, welcome to the world of DaaS!


To your Excel-ling!
Michael Olafusi
0700ANALYTICS
www.urbizedge.com

P.S. We have now fully launched our open class Financial Modelling and Financial Planning course, you can read up on the details and registration steps at https://www.urbizedge.com/FinancialModelling We've spent three years perfecting the curriculum via doing on-request financial modelling training for companies, and building models for both foreign and local clients.

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)




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