+ Reply to Thread
Results 1 to 18 of 18

Printing results from a drop-down list

  1. #1
    Registered User
    Join Date
    09-15-2016
    Location
    NY
    MS-Off Ver
    2010
    Posts
    10

    Printing results from a drop-down list

    Hello,
    I am new here so I apologize if this was posted before, but I am desperate for a solution.

    I have a worksheet with a drop-down list (made from data validation), which pulls data from another worksheet and displays it on the first worksheet. The first worksheet (with the dropdown) is designed to be a document that can be printed out (1 for each item on the dropdown). I am looking for a way to print (or save as a pdf) the worksheet for each of the items on the dropdown rather than saving each one individually). Does anyone know of a way to do this? I can send the file if anyone has any ideas.

    Thank you

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

    Re: Printing results from a drop-down list

    Attaching the file would be a good idea in any case. People are willing to work on an issue if they have a concrete example. It eliminates a lot of the ambiguity. Also, speaking for myself (and possibly others), I'm basically lazy and don't want to set up the problem unless it is exceptionally easy to do so.

    Make sure you change the data so there's no sensitive or proprietary information posted, and we only need enough data to prove the concept or demonstrate the problem. However, if you do have 250,000 rows in the real world, do mention that fact.
    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-15-2016
    Location
    NY
    MS-Off Ver
    2010
    Posts
    10

    Re: Printing results from a drop-down list

    Thank you, here is the file. I am looking to print the worksheet "Scorecard" (a1:q39, selected print area) for each value in the dropdown menu on the same worksheet.
    Attached Files Attached Files

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

    Re: Printing results from a drop-down list

    I think this is what you want. It loops through each value in Column A in the monthly data, sets the filter and saves the result as a PDF file.

    The path to where the PDF files are created is the same as wherever you place this spreadsheet. It's obvious in the code where this is set if you want to change it.

    Also there is one line commented out. I only tested it for the first 3 values. It's set up to run it for every value. It takes between 5 and 10 seconds to make a PDF file. That's a gut check. I haven't really timed it.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    09-15-2016
    Location
    NY
    MS-Off Ver
    2010
    Posts
    10

    Re: Printing results from a drop-down list

    Thank you so much for the feedback, but how would I print all? This may be obvious, but I'm new to anything involving visual basic. If I go to the print option, I only see how to print the current page.

    For Dim MyPath As String ' Path to where you want the PDF files (currently same path as spreadsheet)

    Do I put an actual file path hyperlink to a folder?

    Dim MyFile As String ' File name of the PDF file

    Is there a way to have the files save as the value shown in the dropdown menu, or another piece of data?

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

    Re: Printing results from a drop-down list

    You would have to run the macro - look under the view ribbon. The macro selection is on the end.
    To run it, select Run. You can also select the macro and assign it to a control key by using the option button with the macro selected.
    The macro is called Publish. The code produces one PDF file for each entry.

    To Edit the macro, select Edit

    To change the path, change this line of code:
    MyPath = ThisWorkbook.Path

    To something like:
    MyPath = "C:\MyFolder\MySubFolder"

    Make sure that the path you are trying to save the PDF files to exists.

  7. #7
    Registered User
    Join Date
    09-15-2016
    Location
    NY
    MS-Off Ver
    2010
    Posts
    10

    Re: Printing results from a drop-down list

    Awesome! I was able to print these pdfs to a directory, I just have a question about the naming. I think I see that the name is determined here:

    MyFile = sh.Cells(i, "A") & ".pdf"

    Is there a way that the naming format could be C12_C10 from the "scorecard " sheet (or Column A_Column B from the "month data" sheet)?

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

    Re: Printing results from a drop-down list

    Change this line:
    MyFile = sh.Cells(i, "A") & ".pdf"
    to
    MyFile = sh.Cells(i, "B") & ".pdf"

    You have an issue though. Some of the names are #N/A. This will not translate to a valid filename. File names cannot have a slash in them. Also the cell contains an error, so the program will fail.

    I can "trap" the error and convert the name to N_A, but then you have multiple N_A files that will overwrite one another.

    So how would you like to handle this? I could trap the error and then use the number in column A instead, or I can simply ignore these lines.
    Last edited by dflak; 09-19-2016 at 09:28 AM.

  9. #9
    Registered User
    Join Date
    09-15-2016
    Location
    NY
    MS-Off Ver
    2010
    Posts
    10

    Re: Printing results from a drop-down list

    dlflak,

    The sheet I sent you actually had the real column B deleted, since it has proprietary information. The actual column B will be the actual supplier names, and will not have any "N/A's".

    So I see that MyFile = sh.Cells(i, "A") & ".pdf" [name of file will be Supplier ID]
    and
    MyFile = sh.Cells(i, "B") & ".pdf" [name of file will be supplier name] name the pdf as column A and B from "Month Data" sheet respectively.

    Do you know of a way to use both in the name (possibly separated by and underscore or hyphen)? Example File Name: 000001_Unnamed Supplier

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

    Re: Printing results from a drop-down list

    I am glad to hear that won't be an issue.

    If you want number and name then:
    MyFile = sh.Cells(i,"A") & "_" & sh.Cells(i, "B") & ".pdf"

  11. #11
    Registered User
    Join Date
    09-15-2016
    Location
    NY
    MS-Off Ver
    2010
    Posts
    10

    Re: Printing results from a drop-down list

    Thank you dflak, this works exactly as I would hope.

    I do have one bonus question, but I could live with what we already have if this didn't work. Column A is formatted as custom cell type to make sure there are enough digits when displayed in excel. Many of the #'s begin with a zero, and excel will show them without the first zero if not formatted this way. I noticed the pdf's saving do not include the zero in the front of the number. Do you know of any way to keep the formatting while naming? Thank you again

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

    Re: Printing results from a drop-down list

    MyFile = format(sh.Cells(i,"A"),"00000#") & "_" & sh.Cells(i, "B") & ".pdf"

    Use the format command - pad it with as many zeros as you need. I padded it to 5 places in this example so 1 is 000001 and 100 is 000100.

  13. #13
    Registered User
    Join Date
    09-15-2016
    Location
    NY
    MS-Off Ver
    2010
    Posts
    10

    Re: Printing results from a drop-down list

    Thank you, this appears to be working correctly. I am however getting a saving error when running the macro by the time it gets to the 45th line. When I click "debug", the macro screen highlights this section in yellow:
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
    MyPath & "\" & MyFile, _
    Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
    :=False, OpenAfterPublish:=False

    I did not get an error when running through all rows with what you sent me on Friday, before making the changes to naming convention. Are these changes no longer consistent with the section pasted above? IS there a reason why there would only be in error after 45 rows?

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

    Re: Printing results from a drop-down list

    It looks like the program is trying to create a file name that isn't legal. Run the program again and when it crashes, hover over MyFile in the highlighted line. The program should tell you what the value is. That's the name of the file it is trying to produce. Does it have characters like /\: in it? Does it look like the file name you are expecting?

  15. #15
    Registered User
    Join Date
    09-15-2016
    Location
    NY
    MS-Off Ver
    2010
    Posts
    10

    Re: Printing results from a drop-down list

    I just realized that the name that it stopped at has a / (slash) in it. Is it not possible at all to have slashes as a file name? I'm guessing that is more of a pdf naming issue than a macro issue. I can simply change the names that have slashes, but I am trying to keep naming the same across multiple databases.

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

    Re: Printing results from a drop-down list

    OK, here's the fix for that:

    MyFile = format(sh.Cells(i,"A"),"00000#") & "_" & REPLACE(sh.Cells(i, "B"),"/","_") & ".pdf"

    The REPLACE Command will replace the / with an underscore which is OK in a filename.

  17. #17
    Registered User
    Join Date
    09-15-2016
    Location
    NY
    MS-Off Ver
    2010
    Posts
    10

    Re: Printing results from a drop-down list

    Thank you! You are a wizard!

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

    Re: Printing results from a drop-down list

    Not a wizard: just been at it a long time. Glad to help.

+ 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. extract all results from a drop down list
    By sarinky in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 03-15-2016, 11:42 PM
  2. Drop down list with conditional results
    By RFF in forum Hello..Introduce yourself
    Replies: 2
    Last Post: 03-11-2016, 12:30 AM
  3. [SOLVED] Printing Multiple Options from a Drop-Down List
    By JayPear in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-08-2014, 10:07 PM
  4. Help With Drop-Down List Results
    By dfurn in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 05-16-2013, 10:50 AM
  5. Splitting the results of a drop down list
    By stephen1000 in forum Excel General
    Replies: 8
    Last Post: 01-28-2009, 06:07 PM
  6. [SOLVED] Concatenate Results from a Validated Drop Down List
    By Bill Foster in forum Excel General
    Replies: 2
    Last Post: 04-27-2006, 04:00 PM
  7. Coding drop down list results as numbers
    By chan_siu_man in forum Excel General
    Replies: 1
    Last Post: 03-16-2006, 12:55 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