+ Reply to Thread
Results 1 to 16 of 16

Select a range by user input to create templated workbooks from

  1. #1
    Registered User
    Join Date
    08-24-2015
    Location
    Emsworth, England
    MS-Off Ver
    2019
    Posts
    27

    Question Select a range by user input to create templated workbooks from

    I am hoping someone can help. I have put together the below code but I am now looking to include an option for the user to select the range of cells to generate a seprate workbook per row. Hopefully, via an input box that asks for the first row number and the last row number.

    Below is the code I have so far:


    Please Login or Register  to view this content.

  2. #2
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Select a range by user input to create templated workbooks from

    This example uses the Application.InputBox for the user to select a range and create a new workbook. However, if they select more than one row, then all the selected rows will be in the new workbook. If you want a workbook per row the the user would need to select only one row at a time.

    Example:
    Please Login or Register  to view this content.
    An alternative would be to use a For loop to define the rows, then go through the sheet.add, copy, sheet.copy and SaveAs for each row.
    Example: user wants rows 12:18
    Please Login or Register  to view this content.
    Last edited by JLGWhiz; 11-08-2020 at 06:48 PM.
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

  3. #3
    Registered User
    Join Date
    08-24-2015
    Location
    Emsworth, England
    MS-Off Ver
    2019
    Posts
    27

    Re: Select a range by user input to create templated workbooks from

    Thanks for your time so far. So there is no way to pass a range through user input into the existing code. As the current code creates a template per line and saves each file with a naming convention. I have numerous entries and want to control how many lines are dealt with each time.

  4. #4
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Select a range by user input to create templated workbooks from

    Well, the parameters you describe are confusing.

    looking to include an option for the user to select the range of cells to generate a seprate workbook per row. Hopefully, via an input box that asks for the first row number and the last row number.
    Red text indicates one row = one new file.
    Blue text indicates one to multiple rows = new file.
    The code in the OP indicates non contiguous cells in random order being applied to a template and creating a new file with a single row.

    so while the output appears to be a single row of data, the input comes from multiple rows and columns. That is not conducive to a user making an entry into an input box for a starting row and ending row. Perhaps you want to re-think your approach on this, based on what data will be extracted from the source document to fill the template. Or maybe I just read it wrong.

  5. #5
    Registered User
    Join Date
    08-24-2015
    Location
    Emsworth, England
    MS-Off Ver
    2019
    Posts
    27

    Re: Select a range by user input to create templated workbooks from

    Sorry, I should try to be more specific. Ideally to generate a separate workbook per row. As the form I have above copies a row to a templated workbook and assigns a name based on the cells in that particular row.

  6. #6
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Select a range by user input to create templated workbooks from

    Are you looking for something like this:

    Please Login or Register  to view this content.

  7. #7
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Select a range by user input to create templated workbooks from

    I think I am becoming dyslexic. I have been reading the source and destination sheets in reverse. @maniacb is on the right track with the input box. but I think I would use two inputbox functions (one for start and one for end) to make it more user friendly. I would also use Application.InputBox with Type:=1 to force the user to enter numbers.
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    08-24-2015
    Location
    Emsworth, England
    MS-Off Ver
    2019
    Posts
    27

    Re: Select a range by user input to create templated workbooks from

    Exactly what I wanted thank you both for all the effort. The form works brilliantly well .

  9. #9
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Select a range by user input to create templated workbooks from

    Happy to assist,
    Regards, JLG

  10. #10
    Registered User
    Join Date
    08-24-2015
    Location
    Emsworth, England
    MS-Off Ver
    2019
    Posts
    27

    Re: Select a range by user input to create templated workbooks from

    Is there a way of getting this macro to create a template per line based a column holding value 'y'?

  11. #11
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Select a range by user input to create templated workbooks from

    Which column should be checked for the value 'y'? You can write an if statement inside the for loop to check the "y" condition, but we need to know which column.

  12. #12
    Registered User
    Join Date
    08-24-2015
    Location
    Emsworth, England
    MS-Off Ver
    2019
    Posts
    27

    Re: Select a range by user input to create templated workbooks from

    Column A3 would be where I would put 'Y'.

  13. #13
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Select a range by user input to create templated workbooks from

    Here is an update. Try on a test file, not tested.

    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    08-24-2015
    Location
    Emsworth, England
    MS-Off Ver
    2019
    Posts
    27

    Re: Select a range by user input to create templated workbooks from

    Always amazing thanks. Such a small change, I wasn't uncertain what it was.

  15. #15
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Select a range by user input to create templated workbooks from

    If that takes care of your original question, please select*Thread Tools*from the menu link above and mark this thread as SOLVED.

    Also, as a relatively new member of the forum, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

  16. #16
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Select a range by user input to create templated workbooks from

    Thanks for Rep!

+ 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] Using a macro to create directories and refer to data input by a user, and select a file
    By TnD_Guy in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-18-2018, 04:36 PM
  2. Trying to use user input to select Excel Tab
    By wilster98 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-06-2018, 01:40 PM
  3. Please help with input form, arrays and a function
    By jbaich in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-20-2014, 01:50 PM
  4. Autofilter to select a range from user input
    By santu03 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-31-2013, 12:11 AM
  5. Replies: 1
    Last Post: 03-29-2013, 03:06 PM
  6. Input Box Auto Filtered as Text in a range for user to select periods
    By excelrcb3 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-13-2012, 04:56 PM
  7. User Select Range Through Input Box
    By bdb1974 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-21-2009, 04:47 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