+ Reply to Thread
Results 1 to 7 of 7

Looping through dropdown menu to generate pdf

  1. #1
    Registered User
    Join Date
    06-22-2017
    Location
    USA
    MS-Off Ver
    MS EXCEL
    Posts
    10

    Looping through dropdown menu to generate pdf

    I have set up a file so that the table updates based on the value in the dropdown menu. The drop down menu consists of numbers stored as text (employee ID numbers starting in 0. Hence saved it as a string so that the zeros are not dropped).

    I'm trying to create a code that loops through each value in the drop down menu and generate a pdf for each person, saving the pdf using the person's last name. So far, I've tweaked this code below. The main problem that I noticed is, this code seems to convert the Employee ID numbers into an actual number. (i.e. 000123 becomes 123), leaving me with a "#N/A" where the employee's name should be.


    When I run this code, I get the following error: "Run-time error '13." Would appreciate any help troubleshooting this. I'm so close, yet so far.

    B12 - references the drop down list
    S4 contains the name of the person that updates based on what value is selected in "B12"


    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 06-26-2017 at 10:41 AM. Reason: Added Missing CODE tags, please read the Forum Rules, link above in the menu bar. Thanks.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Looping through dropdown menu to generate pdf

    Perhaps:
    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    08-08-2014
    Location
    Lancaster, PA
    MS-Off Ver
    2016 (windows & mac)
    Posts
    94

    Re: Looping through dropdown menu to generate pdf

    dvCell is defined as a Range object, during your loop you are trying to assign a cell value to it, which is likely the cause of the Error Type 13 (Type Mismatch).

    I'm not sure why you're assigning anything to dvCell in the loop, you don't reference it again. I suspect you can just delete that line.

    I also don't believe you can declare a new variable inside a loop, so the line Dim SaveAsStr As String should be moved outside the loop, ideally at the top with the other declarations.
    Last edited by thatandyward; 06-26-2017 at 11:52 AM.

  4. #4
    Registered User
    Join Date
    06-22-2017
    Location
    USA
    MS-Off Ver
    MS EXCEL
    Posts
    10

    Re: Looping through dropdown menu to generate pdf

    Thank you thatandyward and JBeaucaire. So I revised the code as such, removing the dvCell and moving up the SaveAsStr. It produced one report, but not the others.



    Please Login or Register  to view this content.

  5. #5
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,500

    Re: Looping through dropdown menu to generate pdf

    This code will work as such,

    Please Login or Register  to view this content.
    but for this specific problem
    this code seems to convert the Employee ID numbers into an actual number. (i.e. 000123 becomes 123), leaving me with a "#N/A" where the employee's name should be.
    it maybe best to post an example file to address the problem.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  6. #6
    Registered User
    Join Date
    06-22-2017
    Location
    USA
    MS-Off Ver
    MS EXCEL
    Posts
    10

    Re: Looping through dropdown menu to generate pdf

    Quote Originally Posted by bakerman2 View Post
    This code will work as such,

    Please Login or Register  to view this content.
    but for this specific problem


    it maybe best to post an example file to address the problem.
    Thanks, Bakerman. I ran the code you posted, and it worked for one iteration, producing two reports. But when I tried running it again, I got a "Run-time error" (image posted)


    Here's a link to the file. The script concerns the worksheet at the end called "Table." Basically, I'm trying to generate a report formatted in this worksheet. The dropdown list is in B12, and contains the unique identifiers of each manager we want to generate a report for. Would appreciate any help to figure out how to get the loop to work so that I can generate hundreds of pdfs with a click of a button.

    My colleague and I've gotten the macro to either generates pdfs that don't contain the updated data or produce one report that doesn't loop.
    Last edited by jjykim86; 06-30-2017 at 12:34 PM. Reason: Upload file

  7. #7
    Registered User
    Join Date
    06-22-2017
    Location
    USA
    MS-Off Ver
    MS EXCEL
    Posts
    10

    Re: Looping through dropdown menu to generate pdf

    Figured it out! It was simply a matter of removing one line of code, and now it works!

    Thanks for the input!

    Please Login or Register  to view this content.
    Last edited by jjykim86; 06-30-2017 at 12:38 PM.

+ 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] make dropdown menu dependent on other dropdown menu values
    By kosherboy in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 12-30-2015, 04:29 PM
  2. How a drop down menu's list can change depending on another dropdown menu.
    By sudeepkm73 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 06-30-2015, 03:18 AM
  3. [SOLVED] How a drop down menu's list can change depending on another dropdown menu.
    By marc1980 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 05-21-2014, 04:58 PM
  4. Replies: 1
    Last Post: 03-27-2013, 07:04 AM
  5. [SOLVED] Excel 2007 : new drop down menu based on dropdown menu in previous cell
    By martinpols in forum Excel General
    Replies: 3
    Last Post: 04-30-2012, 02:33 AM
  6. Create Dropdown menu without using the Validation on the Data Menu
    By lostinformulas in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 07-13-2006, 03:47 PM
  7. dropdown menu or Jump menu
    By the dude in forum Excel General
    Replies: 1
    Last Post: 03-26-2006, 02:58 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