+ Reply to Thread
Results 1 to 7 of 7

Set range and title pdf based on cell values

  1. #1
    Forum Contributor
    Join Date
    02-22-2014
    Location
    Winthrop, ME
    MS-Off Ver
    Excel 2010
    Posts
    420

    Set range and title pdf based on cell values

    Good day. I need to find a way to set multiple ranges dynamically (I believe that's what it's called) and then save the data in each range to a separate pdf file that is named based on a specific cell value.

    See example below.

    Pic.jpg

    I would like to set the range based on x's being placed in column A

    The code I'm using to save the files as pdfs is as follows:

    Please Login or Register  to view this content.
    Here is a mock up of my workbook.

    TEST.xlsm

    Thanks.

  2. #2
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Set range and title pdf based on cell values

    You'll need to change the start of the file name Fname to suit your needs. Obviously I can't test it with the file path you have in your example code, and I'm not sure that's where you want the files, anyway.

    Please Login or Register  to view this content.
    I'm interested in starting a career working with VBA, if anyone knows of any opportunities!

  3. #3
    Forum Contributor
    Join Date
    02-22-2014
    Location
    Winthrop, ME
    MS-Off Ver
    Excel 2010
    Posts
    420

    Re: Set range and title pdf based on cell values

    walruseggman,

    Brilliant. It worked first run. Thank you. I'm marking this thread as solved but if you wouldn't mind answering one more question that would be great and if not I understand.

    I'm trying to add a message box to the code you provided so the user can opt to save the files on the share drive or not and when I click "Yes" I keep getting the following run-time error:

    pic.jpg

    Here's the code as it sits now:

    Please Login or Register  to view this content.

  4. #4
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Set range and title pdf based on cell values

    Try adding this line to the macro

    Please Login or Register  to view this content.
    and you can also delete the ".pdf" part in line

    Please Login or Register  to view this content.
    as saving the file as xlTypePDF will add the ".pdf" part on its own.


    Alf

  5. #5
    Forum Contributor
    Join Date
    02-22-2014
    Location
    Winthrop, ME
    MS-Off Ver
    Excel 2010
    Posts
    420

    Re: Set range and title pdf based on cell values

    Alf,

    That did the trick. Thank you kindly. Also, thanks for the tip regarding ".pdf".

    Matthew

  6. #6
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Set range and title pdf based on cell values

    You are welcome.

    Thanks for feed-back and rep

    And as Excel is a most flexible program your problem could be solved in a slightly different way i.e.

    Please Login or Register  to view this content.
    Macro starts by finding the last value in the A column, then it goes from A1 and down till it finds the first value in the A colunm, as this will be the active cell the command
    "ActiveCell.Row" will give the row number, using this value it makes a second jump down the A column and activate the cell where it finds the next value i.e. k.

    The fName is the path (hdd + folder) + Cells(j, 2).Value. Cells is defined by row and column so in the first case where j=2 the Cells(j, 2) is equal to cell vaue of B2 i.e.
    "Micky Mouse"

    And the range to export as a pdf file in the first case is the range B2:E7, and since k = 8, Cells(k -1, 5) is row 7 and column 5 i.e. E7.

    Then macro loops untill k = i

    So as you see a slightly different approach but is it better?? Don't know as this macro reacts on any value found in the A column where as walruseggman's macro only reacts if there is an x in the A column.

    Alf

  7. #7
    Forum Contributor
    Join Date
    02-22-2014
    Location
    Winthrop, ME
    MS-Off Ver
    Excel 2010
    Posts
    420

    Re: Set range and title pdf based on cell values

    Alf,

    Being a novice with VBA it will take me a bit to digest your feedback but I really appreciate you providing the alternate code and the tutorial. I do like the fact that your code doesn't require an "x" given the fact that other users will be inputting data and they may elect to use a different value. I'll give your code a try. Thanks.

    Matthew

+ 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] Displaying multiple values based on several cell values (Sorry about the rubbish title!)
    By Sophie.Durrant in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 04-15-2015, 12:23 PM
  2. Replies: 7
    Last Post: 06-18-2014, 07:15 AM
  3. Sum cells in a range based between two equal cell values in another range
    By sshone1 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-09-2013, 08:12 AM
  4. Need help making a macro to copy range of values based on cell values.
    By zolton in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-23-2013, 08:58 AM
  5. [SOLVED] Need help creating new sheets based on values on a title sheet
    By thesteve in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-04-2013, 07:24 AM
  6. chart title based on Named Range
    By Hammer_757 in forum Excel Charting & Pivots
    Replies: 4
    Last Post: 10-05-2009, 07:34 PM
  7. Range Based on Cell Values
    By Clark in forum Excel General
    Replies: 2
    Last Post: 05-06-2009, 02:56 AM

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