+ Reply to Thread
Results 1 to 14 of 14

INSERT Number of Rows based on Cell Value and populate rows below with initial value

  1. #1
    Registered User
    Join Date
    06-10-2021
    Location
    Wellington New Zealand
    MS-Off Ver
    Office 365
    Posts
    10

    INSERT Number of Rows based on Cell Value and populate rows below with initial value

    Hi there

    Attached is a spreadsheet with two tabs - one includes the starting data, the other Tab shows the result that I am trying to generate from the source data.

    What I am trying to do is insert a number of rows between each row based on the value in Column B. I can do that using the following or code:

    Please Login or Register  to view this content.
    What this refers to is a *.pdf filename and then consequtive page numbering in each PDF document.

    What I want to do is populate the inserted rows with consequtive numbers in the inserted rows below each number in Column A. I also want to generate the individual page number in the PDF document in Column C and populate Column D with the original filename number for each page in that range. It is probably easier to see what I mean by looking at the "Desired output example" tab in the attached spreadsheet.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,943

    Re: INSERT Number of Rows based on Cell Value and populate rows below with initial value

    Please Login or Register  to view this content.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,521

    Re: INSERT Number of Rows based on Cell Value and populate rows below with initial value

    Just a quick question.
    Should Cell B18 in your example not be zero(0) and shift the next three values one cell down?

  4. #4
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,210

    Re: INSERT Number of Rows based on Cell Value and populate rows below with initial value

    Is this output of yours correct...

    Untitled.png

    Another Option...

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by sintek; 10-02-2021 at 03:41 AM.
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  5. #5
    Registered User
    Join Date
    06-10-2021
    Location
    Wellington New Zealand
    MS-Off Ver
    Office 365
    Posts
    10

    Re: INSERT Number of Rows based on Cell Value and populate rows below with initial value

    Hi Jolvanes,

    The numbers 101.#### 201.#### 301.#### represent different sections of a casebook. What is in B11 and B18 are anomoulous as the number of pages for the last document in that section is not calculated correctly using the formula in column B for that document. I need to enter the number of pages for those documents manually but there are usually only three to five sections so that is not a big deal. You will see that in B18 I just entered the number 12 (rather than calculating the number of pages using the forumula) and in B11 the number is 0 (assuming that document 101.0110 is only 1 page).

    I note the file name in D11 is incorrect as Excel truncates the number 0 in that cell. Unless there is an easier way, I can later fix that by making column A a "text" rather than number column. Is there a simpler way to ensure that Excel continues to treat the numer 101.0100 as 101.0100 rather than causing it to become 101.01? This upsets the reference to the underlyling *.pdf file 101.0100.pdf so it would be better if I can ensure the trailing zeros remain.
    Last edited by RolyRobertson; 10-02-2021 at 06:20 PM.

  6. #6
    Registered User
    Join Date
    06-10-2021
    Location
    Wellington New Zealand
    MS-Off Ver
    Office 365
    Posts
    10

    Re: INSERT Number of Rows based on Cell Value and populate rows below with initial value

    Hi Sintek,

    I see that I may have changed the numbers on "sheet 1" as I was playing around with trying to get the filename in Column D of that sheet to show correctly. The desired output in rows 101 and 102 that you have higlighted above are correct in principle, (provided that the input document numbers were 101.0100 and 101.0101 (each of these documents being only 1 page in length).

  7. #7
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,521

    Re: INSERT Number of Rows based on Cell Value and populate rows below with initial value

    I deleted everything except the data in Column A
    It looks like it gives you the result you want.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  8. #8
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,210

    Re: INSERT Number of Rows based on Cell Value and populate rows below with initial value

    If not needing your formulas then...another option...Further to Post 4
    Please Login or Register  to view this content.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    06-10-2021
    Location
    Wellington New Zealand
    MS-Off Ver
    Office 365
    Posts
    10

    Re: INSERT Number of Rows based on Cell Value and populate rows below with initial value

    Jolivanes,

    Thanks. That is a convienient way to do it and it is very helpful to have the "undo result" as well. However it is not quite correct as what is in Column C needs to be 101.0001 in rows C2 to C14 etc (i.e. for the 13 pages in document 101.0001 all File Names must be 101.0001.pdf). If it did that this solution would work fine. A "nice to have" is making the original data in bold in the output as it makes it easy to see the divisions between documents but that is not critical.

  10. #10
    Registered User
    Join Date
    06-10-2021
    Location
    Wellington New Zealand
    MS-Off Ver
    Office 365
    Posts
    10

    Re: INSERT Number of Rows based on Cell Value and populate rows below with initial value

    Sintek

    Thank you that works except that any File name reference number in Column A that ends in 0 (e.g.101.0070 or 101.0110) produces the incorrect file name in Column C for the remainder of the entries for that file reference number because Excel truncates the trailing zero. I haven't worked out how to stop excel from truncating the trailing zero. Any ideas?

  11. #11
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,521

    Re: INSERT Number of Rows based on Cell Value and populate rows below with initial value

    Replace the previous code with this.
    Please Login or Register  to view this content.
    If you want the outcome in a different sheet, that can be done of course.
    The "Undo Result" only works if, before running the code, you copy the data in Column A to somewhere else where you can retrieve it from.
    If you want that to be part of the code, that should be no problem.
    Just let us know.
    Last edited by jolivanes; 10-04-2021 at 05:05 PM.

  12. #12
    Registered User
    Join Date
    06-10-2021
    Location
    Wellington New Zealand
    MS-Off Ver
    Office 365
    Posts
    10

    Re: INSERT Number of Rows based on Cell Value and populate rows below with initial value

    Thanks that works perfectly.

    I just left the "undo result" code attached to that button that was in your previous example and it works for what I need i.e. it returns the sheet back to the starting point. In any event I always have the document identifiers in Column A as they are extracted from the Windows folder container all of the underlying files so I can always repopulate Column A with any numbers I need. It's just convienient in case I missed a row etc.

    Many thanks

  13. #13
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,521

    Re: INSERT Number of Rows based on Cell Value and populate rows below with initial value

    Re: "it returns the sheet back to the starting point." Only when the data of Column A has been copied into a sheet named "Desired output example" from range F2:F21.
    Of course if you delete the copy and paste part out of the code, it does clear the sheet.
    Thanks for letting us know that all is working to your liking and good luck.

  14. #14
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,210

    Re: INSERT Number of Rows based on Cell Value and populate rows below with initial value

    Thank you that works except that any File name reference number in Column A that ends in 0 (e.g.101.0070 or 101.0110) produces the incorrect file name in Column C
    Just change these snippets that appear twice in code
    Please Login or Register  to view this content.
    To
    Please Login or Register  to view this content.
    Attached Files Attached Files

+ 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. Replies: 7
    Last Post: 10-14-2016, 05:33 PM
  2. [SOLVED] Macro to insert specific number of rows, populate rows with data above except date
    By Melissa Camp in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 10-08-2015, 03:59 PM
  3. [SOLVED] How to insert number of rows based on value of a Cell
    By sathyasun in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-24-2013, 12:47 AM
  4. [SOLVED] insert rows based on number in cell and copy the data down into the new rows
    By pziefle in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 05-05-2013, 11:19 AM
  5. [SOLVED] Insert number new rows based on preceeding row. Populate them based on preceeding row.
    By Common Wealth in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-13-2013, 06:44 PM
  6. [SOLVED] Insert Multiple Rows Based Off Number in Cell and Copy Data From Above New Rows
    By tstell1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-02-2012, 04:15 PM
  7. Insert a number of rows based on the value in a cell
    By garridosk in forum Word Programming / VBA / Macros
    Replies: 2
    Last Post: 11-16-2011, 04:41 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