Macro to create a New File with a pivot table and source data table

bearcub

Well-known Member
Joined
May 18, 2005
Messages
734
Office Version
  1. 365
  2. 2013
  3. 2010
  4. 2007
Platform
  1. Windows
I have to create and prepare between 30 to 40 files from a data source to send to the some of our International Sales reps.

We are making a FX commission payment for our Europe organization based upon deals they closed since Feb 1st of this year.

Between creating the source files and sending out individual to each rep receiving payment is going to take at least a day for me to create the task without the aid of a macro.

I'm hoping to find a macro that can create and prepare a file for each rep with the payment details so it will reduce the amount of time it is going to take to complete this task.

I have the data for each rep in a table (the table is between 300-400 lines). Each line represents a payment each rep is to receive for an order they closed.

Is it possible to use the source data to create the following:

1) New File with the rep's name
2) The Person's name as the sheet name
3) Create a pivot table
4) Show the source data below the pivot table

I'm hoping I can find a macro that will help me prepare the files before I have to send out the emails to providing the payment detail for each one of the reps

Thank you for your help in advance

Here is a snapshot of the source data from the main file, the pivot table and the data source table in a new file

Source Data
Person NameCommissionCurrencyRateFX CreditsCustomer NameOrder Item CodeOrder CodeIncentive DateEarning GroupGeography NamePeriod
Alexandra Conroy£132.40GBP3.72%$3,561.04Camelot UK Lotteries LimitedFY23 1H FX Adjustments0063t0000117O5rAAE - Multi Year8/31/22Multi YearNorthern EuropeAugust
Alexandra Conroy£357.13GBP3.72%$9,605.44Länsförsäkringar ABFY23 1H FX Adjustments0063t00000rouBtAAI - Multi Year8/31/22Multi YearNorthern EuropeAugust
Alexandra Conroy£3,006.62GBP3.72%$80,866.17Sky UK LimitedFY23 1H FX Adjustments0063t00000ymAsaAAE - Multi Year8/31/22Multi YearNorthern EuropeAugust
Alexandra Conroy£493.99GBP10.29%$4,802.72Länsförsäkringar ABFY23 1H FX Adjustments0063t00000rouBtAAI - NARR8/31/22NARRNorthern EuropeAugust
Alexandra Conroy£4,158.76GBP10.29%$40,432.42Sky UK LimitedFY23 1H FX Adjustments0063t00000ymAsaAAE - NARR8/31/22NARRNorthern EuropeAugust
Alexandra Conroy£37.38GBP0.74%$5,027.34Camelot UK Lotteries LimitedFY23 1H FX Adjustments0063t0000117O5rAAE - Renewal8/31/22RenewalNorthern EuropeAugust
Macro to create the following results :
1) New File & Sheet with Person Name
2) Pivot Table and
3) Source Data Table:
2) Pivot Table from Source
Customer NameEarning GroupIncentive DateOrder CodeFX Credits Commissions
Camelot UK Lotteries LimitedMulti Year8/31/20220063t0000117O5rAAE - Multi Year3561.04£132.40
Renewal8/31/20220063t0000117O5rAAE - Renewal5027.34£37.38
Länsförsäkringar ABNARR8/31/20220063t00000rouBtAAI - NARR4802.72£493.99
Multi Year8/31/20220063t00000rouBtAAI - Multi Year9605.44£357.13
Sky UK LimitedNARR8/31/20220063t00000ymAsaAAE - NARR40432.42£4,158.76
Multi Year8/31/20220063t00000ymAsaAAE - Multi Year80866.17£3,006.62
Grand Total144295.13£8,186.30
3) Table
Person NameCommissionCurrencyRateFX CreditsCustomer NameOrder Item CodeOrder CodeIncentive DateEarning GroupGeography NamePeriod
Alexandra Conroy£132.40GBP3.72%$3,561.04Camelot UK Lotteries LimitedFY23 1H FX Adjustments0063t0000117O5rAAE - Multi Year8/31/22Multi YearNorthern EuropeAugust
Alexandra Conroy£357.13GBP3.72%$9,605.44Länsförsäkringar ABFY23 1H FX Adjustments0063t00000rouBtAAI - Multi Year8/31/22Multi YearNorthern EuropeAugust
Alexandra Conroy£3,006.62GBP3.72%$80,866.17Sky UK LimitedFY23 1H FX Adjustments0063t00000ymAsaAAE - Multi Year8/31/22Multi YearNorthern EuropeAugust
Alexandra Conroy£493.99GBP10.29%$4,802.72Länsförsäkringar ABFY23 1H FX Adjustments0063t00000rouBtAAI - NARR8/31/22NARRNorthern EuropeAugust
Alexandra Conroy£4,158.76GBP10.29%$40,432.42Sky UK LimitedFY23 1H FX Adjustments0063t00000ymAsaAAE - NARR8/31/22NARRNorthern EuropeAugust
Alexandra Conroy£37.38GBP0.74%$5,027.34Camelot UK Lotteries LimitedFY23 1H FX Adjustments0063t0000117O5rAAE - Renewal8/31/22RenewalNorthern EuropeAugust
Totals8,186.30-144,295.13
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
I ended up creating a pivot table and then filtered on the Person Name field. I then had to manual copy the pivot table (without the name field) to create a static table. I then created went through each sheet where I copied the data table below the pivot table from my original data table. I don't know if it is TMI but I wanted to make it look clean and professional for optics.

Now I have to spend the next few hours sending out the emails to the reps. I have to copy and paste a prewritten statement and then attach the files I just created.

We're probably going to be doing this once a quarter. Hopefully I can find a more efficient way to build all this going forward

I did have the following code from another situation I had earlier in the year:

VBA Code:
Sub Save_All_Sheets_As_Workbooks()
Dim wb1 As Workbook, folder, i As Long
Set wb1 = ActiveWorkbook
On Error Resume Next

    With Application.FileDialog(msoFileDialogFolderPicker)
        .Title = "Please select a folder"
        .AllowMultiSelect = False
        .Show
        folder = .SelectedItems(1)
    End With
    If folder = False Then MsgBox "No folder selected.": Exit Sub
Application.ScreenUpdating = False
    For i = 1 To wb1.Sheets.Count
        If wb1.Sheets(i).Name <> "Master" Then
            wb1.Sheets(i).Copy
                Application.DisplayAlerts = False
                    With ActiveWorkbook
                        .SaveAs folder & "\" & wb1.Sheets(i).Name & ".xlsx", FileFormat:=51
                    .Close
                End With
 
Upvote 0
Forgot to include the last 2 lines of code


Code:
Sub Save_All_Sheets_As_Workbooks()
Dim wb1 As Workbook, folder, i As Long
Set wb1 = ActiveWorkbook
On Error Resume Next

    With Application.FileDialog(msoFileDialogFolderPicker)
        .Title = "Please select a folder"
        .AllowMultiSelect = False
        .Show
        folder = .SelectedItems(1)
    End With
    If folder = False Then MsgBox "No folder selected.": Exit Sub
Application.ScreenUpdating = False
    For i = 1 To wb1.Sheets.Count
        If wb1.Sheets(i).Name <> "Master" Then
            wb1.Sheets(i).Copy
                Application.DisplayAlerts = False
                    With ActiveWorkbook
                        .SaveAs folder & "\" & wb1.Sheets(i).Name & ".xlsx", FileFormat:=51
                    .Close
                End With
            Application.DisplayAlerts = True
        End If
    Next i
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,884
Messages
6,175,173
Members
452,615
Latest member
bogeys2birdies

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top