+ Reply to Thread
Results 1 to 25 of 25

VBA to split commissions from one sheet to multiple sheets and summarize by account type

  1. #1
    Registered User
    Join Date
    09-14-2018
    Location
    USA
    MS-Off Ver
    Office 2016
    Posts
    23

    VBA to split commissions from one sheet to multiple sheets and summarize by account type

    Hey this is my first time posing a question. Up to this point, I have been able to scour the internet for formulas or macros to help me create complex Excel files that automate tasks. This situation is a little more complex and I need some help from someone much smarter than me.

    What I'm trying to do is this:
    1. Each month I get a commissions payout report from SalesForce and export to Excel. I copy and paste it into an Excel template with the macros.
    2. This data lists all of the customers that had salespeople on it and the commissions that they earned in the prior month. There could be anywhere from 1-4 salespeople per account. It is possible that there is no salesperson in the Salesperson 1 field but there are salespeople in the other salespeople fields.
    3. Then I would like to run a macro that takes that report data and creates a new tab in Excel for each salesperson. Since there are 4 columns for salespeople, a particular salesperson could be listed in any of those 4 columns and I would need the macro to be able to find a particular salesperson and extract their commissions for each customer no matter which column they were in. If there are multiple salespeople per account, then that customer could appear on each salesperson's report with the corresponding commissions. Our current method is to create a PivotTable, select the salesperson then print. We would then change the PivotTable to select Salesperson 2, 3, and 4 and sum all the data from those 4 pivots to create the final report, but with 40+ salespeople and more getting added in the future, that process is cumbersome. Another way we used to do it was to create a report per salesperson from SalesForce but running 40+ individual reports took too long.
    4. After all of the sheets are created for each salesperson, we would like to summarize that data on each of those sheets based on the type of account: Electric or Gas. If we can do this step with step 3 that would be ideal.

    The SalesForce report spits out additional columns that are not needed for this task so the file that is attached only has columns for the criteria that I need for the macro. The info in the file is also for examples only. It includes a tab called Ideal Report which shows how we would like to see the report for each salesperson.

    Please include comments where you change code so that I can follow it and make changes to variables if I need to. I'm hoping this is possible.

    Research:
    I was going to post my code from the macro here but my company's firewall is preventing me from doing it. Arg. Anyways, it's in the file.

    Functions needed for this code are located in another module in the example file. Those seem to work fine.

    After changing the column value to "N" for the range of data, and the criteria column to "7" for Column G, I can't get my headers in row 6 to copy over to each of the new sheets. I'm at a loss on how to get them back.

    Any help would be appreciated! Thanks!
    Attached Files Attached Files
    Last edited by xceler8or; 09-25-2018 at 11:48 AM.

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,919

    Re: VBA to split commissions from one sheet to multiple sheets and summarize by account ty

    This can be done with VBA, but you are limited to a maximum of 4 sales people. To get the maximum flexibility from the data it is best to get it in a normalized format.

    I have a routine that helps with this. I took your data and copied into the Source Data sheet in Normlized_Data.xlsb. On the Control Panel I configured it so it would "keep" columns A:F and "normalize" the rest.

    Running the macro in this program produced the results in the normalized data tab. I copied this data back to your workbook in a tab called Data 1.

    Under most circumstances, the normalized data function produces valid normalized data. However, in this case, you had peoples' names and commission amounts interspersed. So I had to do another adjustment. The data came out with the commission data directly under the person data, do I used a formula to bring the commission up to the same line with the person, and then put a filter in place to identify lines with people on them (a numerical value in Column I). I filtered for true, and copied the data into another table on sheet Data 2.

    Sheet Data 2 has the true normalized data and this is the format in which you should be entering data in the future (more on that later).

    I built a pivot table from this data and "inserted" a slicer. This is only one way to look at the data. Since the data is normalized, you could build a pivot table filtered by customer and which sales people worked on the account.

    The normalized data format on Sheet Data 2 is not that intuitive. What I suggest in this case is to build a User Input from to collect the data for columns A:F and then select sales people and enter the commission. A click of the button on the form will append the record to the database.

    All of the two-stepping with getting the data into a normalized format is a one-time shot for legacy data.

    Looking at the data, I just came up with another idea. You can establish a table that contains the following information: Account Number, Customer Name, Type of Account (Gas or Electric), Sign Date, and Renewal Year.

    Then when it comes time to do data entry, you select a Customer Name from a drop-down list in one column and the type of account in another column and the program will look up the rest of the data, so all you need to do is add the sales person and the commission. You will probably want to have another table for data validation for sales people. Add them as you need them.

    Let me know if you would like to pursue this approach. In the meantime, have fun playing with the pivot tables.
    Attached Files Attached Files
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  3. #3
    Registered User
    Join Date
    09-14-2018
    Location
    USA
    MS-Off Ver
    Office 2016
    Posts
    23

    Re: VBA to split commissions from one sheet to multiple sheets and summarize by account ty

    Hi dflak, thanks for responding. Sorry if my post was confusing but there are 4 salesperson fields and any combination of 1-4 people from our 40+ salespeople pool could be in those fields.

    You said that you used Normlized_Data.xlsb. Is that a file that you created? Would that be something that you could send me to help in future reports? You also said that this could be done via VBA but you used a different method. Would it be possible to edit the code that I currently have to make this work in my macro?

  4. #4
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,154

    Re: VBA to split commissions from one sheet to multiple sheets and summarize by account ty

    there are 4 salesperson fields and any combination of 1-4 people from our 40+ salespeople pool could be in those fields.
    Quick question....
    According to your upload...is Columns G to N the 4 salespersons fields you are referring to...
    Does that remain constant?
    Is Tucker Investments LLC as salesperson?
    Is row 6...the heading...constant?
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  5. #5
    Registered User
    Join Date
    09-14-2018
    Location
    USA
    MS-Off Ver
    Office 2016
    Posts
    23

    Re: VBA to split commissions from one sheet to multiple sheets and summarize by account ty

    sintek,

    Yes the columns that are in the example file will stay the same for every report. What changes is everything in those columns. As you can see in the file, sometimes there are salespeople listed in the salesperson 3 field when salesperson 1, 2 and 4 are empty. This is not something we are able to change in SalesForce because of how everything was set up years ago. Some salespeople have business names. The data does not need to start in row 6 for the headings. That is just how the macro is set up. If it makes it easier to have the copying and pasting of the report in a new tab with the headings on the first row and have the macros on a separate tab then that would be fine too. Does that answer your question?

  6. #6
    Registered User
    Join Date
    09-14-2018
    Location
    USA
    MS-Off Ver
    Office 2016
    Posts
    23

    Re: VBA to split commissions from one sheet to multiple sheets and summarize by account ty

    I tried to organize the data in the way that dflak did. For some reason, the macro wants to pull the headers from row 10 of the Data 2 tab and I can't find in the code where to change that, so that is why the data is shifted down that far on the Data 2 tab. I've successfully organized the data in a way that the existing macro is able to create new tabs for each salesperson as long as there aren't any cells with formulas in them below the data set. I tried to follow dflak's ideas but would like to avoid the pivot table route if that's possible. Is there any way to make the new tabs from the macro create something similar to the Ideal Report?

    Would it be easier to create a macro for the report per salesperson from my original file or from the file attached to this post? I'm open to suggestions.

    I appreciate anything that can help me find a solution.
    Attached Files Attached Files

  7. #7
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,154

    Re: VBA to split commissions from one sheet to multiple sheets and summarize by account ty

    Perhaps a bit unorthodox....Works for your initial upload...Perhaps someone else can simplify...
    Did not have much time...will revisit the code tomorrow and see if I can simplify...and change formats...
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    09-14-2018
    Location
    USA
    MS-Off Ver
    Office 2016
    Posts
    23

    Re: VBA to split commissions from one sheet to multiple sheets and summarize by account ty

    sintek. You, sir, are a genius! Thanks for the help. I never would've figured all of this out. I can work with this. dflak thanks for your help too.

  9. #9
    Registered User
    Join Date
    09-14-2018
    Location
    USA
    MS-Off Ver
    Office 2016
    Posts
    23

    Re: VBA to split commissions from one sheet to multiple sheets and summarize by account ty

    I'll figure out how to mark this thread as solved later tonight

  10. #10
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,919

    Re: VBA to split commissions from one sheet to multiple sheets and summarize by account ty

    My apologies for not responding sooner. Busy here for a Friday.

    Here is the normalization "thing" with documentation. It is useful mostly as a one-time shot for converting legacy data. I recommend copying in your data in place of the raw data and run the macro. Then you can copy the results to a "real" program.

    Unfortunately, your data didn't quite fit the mold. So I had to do an additional adjustment.

    But I see you have a working version so, good luck!
    Attached Files Attached Files

  11. #11
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,154

    Re: VBA to split commissions from one sheet to multiple sheets and summarize by account ty

    Herewith updated with correct formats...
    Tx for rep...Good luck
    Attached Files Attached Files
    Last edited by sintek; 09-22-2018 at 02:30 AM.

  12. #12
    Registered User
    Join Date
    09-14-2018
    Location
    USA
    MS-Off Ver
    Office 2016
    Posts
    23

    Re: VBA to split commissions from one sheet to multiple sheets and summarize by account ty

    Thank you for all the help. This is truly awesome!

  13. #13
    Registered User
    Join Date
    09-14-2018
    Location
    USA
    MS-Off Ver
    Office 2016
    Posts
    23

    Re: VBA to split commissions from one sheet to multiple sheets and summarize by account ty

    I'm not sure if this is the right way to do this but I unsolved this thread because after testing this file with real data, I came across a few errors. First, I realized I needed an extra formatting step to get the data from the report to fit the data for the macro to run. That was easy I thought, so I created a new tab and had formulas on Sheet1 link to the Data tab. The macro threw me an Error 13 mismatch so after erasing the formulas and deleting that other tab, the macro ran without errors. This I can do before inserting the report data into this file so that is not a big issue.

    What I'm not sure how to fix is when a customer has multiple accounts with us that gives multiple commissions for multiple account types, they are all listed separately on a salesperson's report. For some reason I can't upload screenshots so I will do my best to describe. If salesperson 1 has 5 gas accounts with customer 1 and 10 electricity accounts with customer 1, each of the gas and electricity accounts and their corresponding commission amounts will be listed separately. Would it be possible to summarize the account type per customer so that it appears as it did in sintek's latest upload (post #11)? So all the gas accounts for customer 1 would only have 1 commission amount, all electricity accounts for customer 1 would have 1 commission amount, etc. There are several more account types.

    Also, some salespeople have their headings all messed up and the totals fields are out of place. Others have extra blanks.

    I included a few of the salespeople reports after the macro is run as examples. It is better to visualize in my mind.

    Would it be possible to fix these errors?

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by xceler8or; 09-24-2018 at 02:05 PM.

  14. #14
    Registered User
    Join Date
    09-14-2018
    Location
    USA
    MS-Off Ver
    Office 2016
    Posts
    23

    Re: VBA to split commissions from one sheet to multiple sheets and summarize by account ty

    Yes, some accounts will show zero dollars for commission and that is ok
    Last edited by xceler8or; 09-24-2018 at 02:06 PM.

  15. #15
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,154

    Re: VBA to split commissions from one sheet to multiple sheets and summarize by account ty

    I came across a few errors
    Cannot recreate ... need an upload of your actual setup to go through...
    The code was written for your thread upload....Any changes to this will render the code null & void...
    Also, some salespeople have their headings all messed up and the totals fields are out of place. Others have extra blanks.
    Is there any pattern...
    Last edited by sintek; 09-24-2018 at 02:46 PM.

  16. #16
    Registered User
    Join Date
    09-14-2018
    Location
    USA
    MS-Off Ver
    Office 2016
    Posts
    23

    Re: VBA to split commissions from one sheet to multiple sheets and summarize by account ty

    Ok, I'll work on this. I'll need to do a lot of find and replace to protect customer information. Should have it done by tomorrow.

  17. #17
    Registered User
    Join Date
    09-14-2018
    Location
    USA
    MS-Off Ver
    Office 2016
    Posts
    23

    Re: VBA to split commissions from one sheet to multiple sheets and summarize by account ty

    I'm doing my best to understand the code but it's been awhile since I had Visual Basic .NET in college

    I have it set up so that I can paste my report data into the Data tab and Sheet1 pulls that data and formats it properly. I found a workaround to the tab length restriction of 31 characters. It's not in this file because I changed the salesperson names but for salespeople that have more than 31 characters, it does a vlookup on Sheet2 and replaces it with an abbreviated name. I also added a disclaimer macro to run at the end of the CreateReports macro to insert a short disclaimer at the end of the data on each tab.

    I changed the paste command to be PasteValuesAndNumberFormatting which seems to have partially fixed some of the data that was populating the new tabs. The dates are now correctly showing on the salesperson tabs, however, I'm still having trouble with the layout of some of the reports. I'm hoping that by changing the paste command I haven't messed up anything else.

    Would you be able to help me figure out why the formatting doesn't work as it did in the original sample file? I tried to have that sample file be similar to the way the actual report looks. I opened the sample file again and made a second ABC Corporation electric account and the formatting came out the same as the report attached to this post.

    Anything you can do to help would be greatly appreciated.
    Attached Files Attached Files
    Last edited by xceler8or; 09-24-2018 at 04:50 PM.

  18. #18
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,154

    Re: VBA to split commissions from one sheet to multiple sheets and summarize by account ty

    Instead of re-inventing the wheel...
    Please Login or Register  to view this content.

  19. #19
    Registered User
    Join Date
    09-14-2018
    Location
    USA
    MS-Off Ver
    Office 2016
    Posts
    23

    Re: VBA to split commissions from one sheet to multiple sheets and summarize by account ty

    This fixed the formatting issue I had. After running the macro, I deleted all but Salesperson 1's sheet. For this Salesperson, there were multiple gas and electric accounts for Customer 104. Would it be possible to make one line under Customer 104 for gas and sum those accounts for commission? Also, the same for the other account types for each customer and each salesperson?
    Attached Files Attached Files

  20. #20
    Registered User
    Join Date
    09-14-2018
    Location
    USA
    MS-Off Ver
    Office 2016
    Posts
    23

    Re: VBA to split commissions from one sheet to multiple sheets and summarize by account ty

    If there are multiple dates for the electric or gas accounts under one customer, would it be possible to return the max value?

  21. #21
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,154

    Re: VBA to split commissions from one sheet to multiple sheets and summarize by account ty

    In future please ... when posting a thread ... Express you entire requirement from the start with actual workbook scenario setup so that we do not waste unnecessary time on coding...Every request becomes more and more advanced and requires major changes to initial code which worked for initial setup...
    This should solve...
    Please Login or Register  to view this content.
    If there are multiple dates for the electric or gas accounts under one customer, would it be possible to return the max value?
    What dates are you referring to..Three columns contain dates...
    Last edited by sintek; 09-25-2018 at 11:06 AM.

  22. #22
    Registered User
    Join Date
    09-14-2018
    Location
    USA
    MS-Off Ver
    Office 2016
    Posts
    23

    Re: VBA to split commissions from one sheet to multiple sheets and summarize by account ty

    All three columns. Two of the columns have the date format but the renewal column contains just the year.

    I apologize for the extra work. I realize being new to asking for help like this is no reason not to be clear about what I wanted from the beginning. I will make sure it is more explained in the future.

  23. #23
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,154

    Re: VBA to split commissions from one sheet to multiple sheets and summarize by account ty

    Seems to me the top most dates are always the latest so no need for code there...

  24. #24
    Registered User
    Join Date
    09-14-2018
    Location
    USA
    MS-Off Ver
    Office 2016
    Posts
    23

    Re: VBA to split commissions from one sheet to multiple sheets and summarize by account ty

    Thank you so much sintek! This works perfectly now. Some day I'm hoping I'll be able to code something like this myself.

  25. #25
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,154

    Re: VBA to split commissions from one sheet to multiple sheets and summarize by account ty

    ...................................
    Thanks.gif

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Split one Sheet into multiple sheets
    By puneetjain in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-14-2018, 04:19 AM
  2. Replies: 4
    Last Post: 06-13-2014, 01:20 PM
  3. [SOLVED] Split Data from one sheet into multiple sheets
    By jstewart22 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-11-2013, 06:54 PM
  4. need vba to split sheet into multiple sheets
    By thuff in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-20-2013, 04:39 PM
  5. [SOLVED] Split large sheet in multiple 1000 row sheets
    By thotosch in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-14-2013, 06:29 AM
  6. [SOLVED] Split master sheet data to multiple sheets in same workbook
    By Apple Ling in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-26-2012, 10:39 PM
  7. i need to split excel work sheet into multiple sheets
    By samehnabil in forum Excel General
    Replies: 1
    Last Post: 08-16-2012, 07:54 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1