+ Reply to Thread
Results 1 to 27 of 27

Using macros to save drilldowns with file names.

  1. #1
    Registered User
    Join Date
    02-17-2020
    Location
    London
    MS-Off Ver
    Microsoft 365
    Posts
    40

    Using macros to save drilldowns with file names.

    Good afternoon,

    I am currently trying to create a macro where pivot table subtotals are taken and split by their client.
    Once the file is opened, the columns have to be autofit, and the sheet has to be saved as the name of the client.

    I've tried multiple methods without success.

    Also, the potential client list is 45, and I have 30 regular ones; will I have to create it with all 45 in the pivot table in case they appear one week.

    Any help would be appreciated.

    Thank you.

    So on the attached example I will have to click on the subtotals.
    Initially B4
    In this case there doesn't have to be any auto fit adjusting but in the actual data I will have to, then I want to save the file as the name of the client A.
    Either from their own workbook or the summary work book.

    The order of the clients might change and also some maynot be present next week, while some new ones maybe.

    Is there a way to create a macro to handle this and the many variables at play.

    Thank you.
    Attached Files Attached Files
    Last edited by sahmed95; 02-17-2020 at 12:27 PM.

  2. #2
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Using macros to save drilldowns with file names.

    I want to save the file as the name of the client A.
    What's up if the file already exists ?
    Is the file to be recorded in the same folder as the one with data ?
    You want to fire the macro only when clicking in column "B" or do it for the full set of values ?
    Last edited by PCI; 02-17-2020 at 01:56 PM.
    - Battle without fear gives no glory - Just try

  3. #3
    Registered User
    Join Date
    02-17-2020
    Location
    London
    MS-Off Ver
    Microsoft 365
    Posts
    40
    Quote Originally Posted by PCI View Post
    What's up if the file already exists ?
    Is the file to be recorded in the same folder as the one with data ?
    You want to fire the macro only when clicking in column "B" or do it for the full set of values ?
    Hi, the files will be saved in a new folder every week.
    The pivot table is only taking client name and total

    I want to then double click the totall to see backing data and save this for each client (this will then be emailed to them)

  4. #4
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Using macros to save drilldowns with file names.

    the files will be saved in a new folder every week.
    What's the name of the folder?
    Can you attach an example of the final file for a client: There is not so much information inside ...!

  5. #5
    Registered User
    Join Date
    02-17-2020
    Location
    London
    MS-Off Ver
    Microsoft 365
    Posts
    40

    Re: Using macros to save drilldowns with file names.

    Good morning.

    I have attached a new example file.

    In the file we have two reports with different sets of info.

    Report B has price whereas Report A has time and location.

    We need all of this info to send to the client. A simple vlookup grabs the right info from B into A.

    This information will be put into a pivot table. Client name and Price.

    Now when we click on the price we can see that clients, location time and price - this information will be sent.

    So essentially I am looking to automate the opening of each subtotal, autofitting the columns (the real data has some long lines) and then saving that file by the name of the client, their name will be present in the file, in B2.

    The thing that will add complexity to this is that some weeks we may have clients A, B and D, or maybe even E, F and G.

    Every macro I have run copies the client name, but "types" the value instead of pasting it.

    Can the macro accommodate a large list of clients - in my example file I have added clients D, E and F, in this example I only have six possible clients, the macro will have to be written for all 6, I then grab ones with active data?

    And lastly, they will all be saved in a folder probably named, client backups 21.02.2020

    I hope this makes sense, thank you!
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    02-17-2020
    Location
    London
    MS-Off Ver
    Microsoft 365
    Posts
    40

    Re: Using macros to save drilldowns with file names.

    Hey,

    I replied below, thought I'd reply to your message too.

    Thanks.

  7. #7
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Using macros to save drilldowns with file names.

    Is the folder' name where to store files (client backups 21.02.2020) will be manually entered or do we need to create the folder?
    What is the use of "Report B" while all information is already recorded in "Report A"
    Last edited by PCI; 02-19-2020 at 07:36 AM.

  8. #8
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Using macros to save drilldowns with file names.

    For a first step see next code
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    02-17-2020
    Location
    London
    MS-Off Ver
    Microsoft 365
    Posts
    40

    Re: Using macros to save drilldowns with file names.

    Hi, I can create these folders weekly.

    Once I have the address I can enter it via VBA.

    Report B has some information that Report A doesn't
    This information is vlookup'ed from B into A

    The one with 'more' information is used to create the pivot table.

    I have just seen your vba code, thank you so much. I will give it a go now!

    Thank you!

  10. #10
    Registered User
    Join Date
    02-17-2020
    Location
    London
    MS-Off Ver
    Microsoft 365
    Posts
    40

    Re: Using macros to save drilldowns with file names.

    Quote Originally Posted by PCI View Post
    For a first step see next code
    Please Login or Register  to view this content.
    The test run was successful!

    Thanks!

  11. #11
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Using macros to save drilldowns with file names.

    You're welcome

  12. #12
    Registered User
    Join Date
    02-17-2020
    Location
    London
    MS-Off Ver
    Microsoft 365
    Posts
    40

    Re: Using macros to save drilldowns with file names.

    Can I send over a live version, with dummy data of course

    And then if you could just let me know what the 'variables are'

    i.e what can I change in the code to keep it working across different examples

    I think const is constant

    I could see report a, report b and client backups 21.02.2020 in the code and can change these accordingly.

    I can't thank you enough for the help, I am not just sitting idly, I am currently learning about power bi and vba's to try and complete things like this in the near future.

  13. #13
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Using macros to save drilldowns with file names.

    Can I send over a live version, with dummy data of course
    Yes of course

  14. #14
    Registered User
    Join Date
    02-17-2020
    Location
    London
    MS-Off Ver
    Microsoft 365
    Posts
    40

    Re: Using macros to save drilldowns with file names.

    Hi,

    I have attached the file.

    In this sheet the headers are accurate.

    In 'Transport' there are 5 columns highlighted in yellow that we need in 'Access'

    Access has the full data and some lookups to stich together a client backup sheet.

    Pivot summarises all of this information.

    The macro idea was to get the backups automatically.
    Saved in a folder.

    I'm not too sure if your macro retrieved the information via the Pivot tables or the worksheets.

    I have tried porting your code over to this sheet but as the references/ anchors are different I get errors I cannot debug... If you wouldn't mind sending some annotations I could try rewriting it, or at least understanding the code and the resulting actions.

    Thanks once again.
    Attached Files Attached Files

  15. #15
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Using macros to save drilldowns with file names.

    your macro retrieved the information via the Pivot tables
    The Pivot table is not used
    The idea is to prepare a client name list from sheet "Report A" : see the use of the Dictionary
    Then for each record from this list a filter is used in sheet "Report A" to select the corresponding client in column "B"
    Then the complete set of visible cells is copied and pasted into a new file

    As for as I have understood your need and using your last sample file this could be done, using sheet "Access" and coping and pasting only values to the new file.
    In the other hand the folder where files are stored, could be prepare by the macro using for folder's name the week number of the actual day.
    What do you thing ?

  16. #16
    Registered User
    Join Date
    02-17-2020
    Location
    London
    MS-Off Ver
    Microsoft 365
    Posts
    40

    Re: Using macros to save drilldowns with file names.

    I'm sorry. I understand you... but at the same time I don't.

    I've been trying to understand the code all night.

    When i try using the macro on the new example sheet it errors here:
    Set Ws1 = Sheets(WsInN1): Set Ws2 = Sheets(WsInN2)

    Could you physically screen capture your steps, or annotate the macro step info please, so I can learn the code and apply it to my live data file.

    The only other thing I can think of is only using the access sheet; since this one has the complete transport info aswell as the lookups...

    All i need to do is tell excel to look up cons. code, split their info into a new workbook, save the file as the client name - in a folder in my desktop?



    update, I've just made a macro that splits out all workbooks and saves as pdfs-- they save on my desktop, not a folder in my desktop but I have tomorrow to fix that 😂. Now I think I just need to get the first part:

    Having the access data split by code, and having worksheets named by this code
    Last edited by sahmed95; 02-19-2020 at 08:06 PM.

  17. #17
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Using macros to save drilldowns with file names.

    Here what could be done
    go step by step to see what's happening

    Please Login or Register  to view this content.

  18. #18
    Registered User
    Join Date
    02-17-2020
    Location
    London
    MS-Off Ver
    Microsoft 365
    Posts
    40

    Re: Using macros to save drilldowns with file names.

    Quote Originally Posted by PCI View Post
    Here what could be done
    go step by step to see what's happening

    Please Login or Register  to view this content.
    Thank you, will be in the office soon. I'll give it a try

    Really appreciate your help!

  19. #19
    Registered User
    Join Date
    02-17-2020
    Location
    London
    MS-Off Ver
    Microsoft 365
    Posts
    40

    Re: Using macros to save drilldowns with file names.

    It's all working great, I just need the option to sometimes save the files as excel sheets.

    What do I need to change the code to?

    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
    Filename:=WkPh & "\" & K & ".pdf", _

    I'm guessing these have to changed to xslx or something along those lines?
    Last edited by sahmed95; 02-20-2020 at 07:13 AM.

  20. #20
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Using macros to save drilldowns with file names.

    If you want to save as excel file see first macro
    use
    ActiveWorkbook.SaveAs WkPh & "\" & K
    instead of
    ActiveWorkbook.Close SaveChanges:=False ' Quit without saving

  21. #21
    Registered User
    Join Date
    02-17-2020
    Location
    London
    MS-Off Ver
    Microsoft 365
    Posts
    40

    Re: Using macros to save drilldowns with file names.

    It's just pulling the titles, no data...
    Last edited by sahmed95; 02-20-2020 at 10:32 AM.

  22. #22
    Registered User
    Join Date
    02-17-2020
    Location
    London
    MS-Off Ver
    Microsoft 365
    Posts
    40

    Re: Using macros to save drilldowns with file names.

    Hi PCI,

    So in the intial code it's taking the code from B and splitting based on that, the cons. code is in A however.

    I tried editing the code replacing B with A but im guessing there's more to edit.

    When I swap columns B with A theres no problem.

    Can we just swap the code to pick up column A and I think we're done!

  23. #23
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Using macros to save drilldowns with file names.

    Here an update to play with column "A"
    Please Login or Register  to view this content.
    Last edited by PCI; 02-20-2020 at 11:54 AM.

  24. #24
    Registered User
    Join Date
    02-17-2020
    Location
    London
    MS-Off Ver
    Microsoft 365
    Posts
    40

    Re: Using macros to save drilldowns with file names.

    Hi
    Do you know his I can mark this as solved?

    Thank you once again for your help

    I'm learning VBA from https://youtu.be/G05TrN7nt6k

    How long do you think it'd take me to create everything I've asked you on my own from scratch?

  25. #25
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Using macros to save drilldowns with file names.

    Do you know his I can mark this as solved?
    As requester you have the option to mark it as solved, have a look in the menu
    Thank you once again for your help
    You're welcome, so keep in mind to close the loop with a reputation (if you want): See the start on the bottom left corner

    Please Login or Register  to view this content.
    I woyuld suggest to review threads in this forum and try to solve them: I learnt a lot trying to do it and reviewing answer from others

    How long do you think it'd take me to create everything I've asked you on my own from scratch?
    I don't, konw, it's up to you, to the time you can spend on it, to your skill, knowledges and support: Perhaps see for a teacher to help you to start.

  26. #26
    Registered User
    Join Date
    02-17-2020
    Location
    London
    MS-Off Ver
    Microsoft 365
    Posts
    40

    Re: Using macros to save drilldowns with file names.

    Do you teach?

    I tried giving rep but it's saying I need to share it out among other first haha.

    Going to try and code some myself now.

  27. #27
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Using macros to save drilldowns with file names.

    I tried giving rep but it's saying I need to share it out among other first haha.
    You already did it , Tthank you, so nothing to tell you more on the subject

+ 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. [SOLVED] Macro to open Excel file, run other macros save, and close file & repeat.
    By Ronnet2 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-08-2015, 09:47 AM
  2. Need macro that opens .txt file in excel, run macros and save file in batch
    By khalidness in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-11-2014, 11:00 AM
  3. Replies: 15
    Last Post: 08-27-2012, 10:13 AM
  4. Macros To Save Worksheet as New xlsx file & Save Another Worksheet As A Text File
    By KeithT in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 11-16-2011, 05:13 PM
  5. changing file names with macros
    By trevor@OML in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-09-2005, 12:25 PM
  6. multiple file names in macros
    By tfcc in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-09-2005, 02:05 PM
  7. [SOLVED] save excel file from a table delimited file (.txt) using macros
    By sedamfo in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 02-15-2005, 01:06 AM

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