Opening a new file with pivot table data in it

Nelsini

New Member
Joined
May 13, 2021
Messages
25
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
  2. MacOS
Hello!

As the tittle says, I want to open a new file with data from the original file. In the original file we have a pivot table (Daily_report_tbl) with 6 columns and we need to copy the first 3 into the new file. The row number varies from day to day so I can't just copy from row x to row y.
The copied data doesn't need to be turned into a table, I just need the values.

Here is the code I have so far:

VBA Code:
Sub createFile ()
    Dim reportPath As String
    
    reportPath = ActiveWorkbook.Path & "\" & "2.Emails" & "\"
    
    Dim newWB As Workbook
    Set newWB = Workbooks.Add
    
    newWB.SaveAs reportPath & Format(Now, "yyyy-mm-dd") & "_dummyfile.xlsx"
    
End Sub

I don't really know how to incorporate the copy and paste of the table since I can't find anything online..

Any help is appreciated and thanks in advance!!!
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
The same could be achieved with Power Query, saved in a template file.
Short description (UI driven):
- data - from file - from excel
- select file then select the sheet where the pivot is
- maybe remove TOP rows (to start where you'd have titles)
- select columns to keep (remove other columns)
- filter out "nulls" on one of the columns (end of range).
- load as table

Save this file as xltx and confirm this message.
1629105925904.png


Double click to create a new file based on the template.
Save as is a manual step in this case (though you can save a macro file too using xltm.)
 
Upvote 0
Solution
Well this is a file with several macros and we can't really remove any lines in the file. Context:

This is a pivot table that gathers info on 3 to 5 different excel files that are retrieved daily from Splunk. We have several macros assigned to different buttons and one of them is to create the new xlsx file that we use to input the values into a unix script. We copy the values manually from the first excel to the new one, and I wanted this to be automatically done when opening the new excel.

Sorry for any typos and I appreciate the help!!
 
Upvote 0
Hi, context always matters. I'm just thinking the button could call the template (and not make it).
 
Upvote 0
Well I'd prefer a VBA solution but I'll take a look at creating excel templates since I didn't know that was a thing. Thank you for all the help!

(Still looking for a VBA solution if anyone can provide one!! :D)
 
Upvote 0
I tried to help ;)... At least you are now looking into something that might be of use: templates.
Maybe this can help you further (and potentially some other threads over here as well if you look for VBA for dynamic range)
 
Upvote 0
I tried to help ;)... At least you are now looking into something that might be of use: templates.
Maybe this can help you further (and potentially some other threads over here as well if you look for VBA for dynamic range)
Well, looking into templates, I can't really seem to get the template table to stay filtered (we filter the original table by day since it's a daily proccedure). Any thoughts?
 
Upvote 0
Nothing on top of my mind. When I make templates, it never holds data to be filtered.
Since you're using macro's, can't the macro set the correct filter?

Do take note I'm not using VBA anymore since about 10 years. Can't help in that area.
 
Upvote 0
Well I tried to set up a macro to do so, but since I don't really understand VBA that much we're just giving up on the ideia of automatically pasting the data. It's only a couple of clicks anyways, no one will die due to 15 seconds of copy and paste haha but thanks anyways!!
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

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