+ Reply to Thread
Results 1 to 9 of 9

Insert rows based on user input from cell value in other sheet

  1. #1
    Registered User
    Join Date
    10-30-2011
    Location
    Southeastern USA
    MS-Off Ver
    Excel 2007
    Posts
    8

    Insert rows based on user input from cell value in other sheet

    Hello,

    This is my first post here and I'm looking for a macro that will dynamically insert a specific number of rows based on the user's input to a cell that will be on a different sheet in the workbook.

    Basically, I will have an initial column pre-filled with (date) formulas in each row. When I first build the column, I won't have any blank rows between the date-filled rows, but then I want the user to specify a numeric value "X" in a cell on a different sheet and then have the macro insert "X" number of rows underneath each dated row. It would need it to adjust the inserted rows dynamically whenever the user changes the "X" value.

    I have included a sample sheet of data to show my expected outcome. I had to .zip it because it wouldn't upload as an .xlsx file for some reason. Thank you for any assistance!
    Attached Files Attached Files
    Last edited by MrPisky; 10-31-2011 at 09:03 PM.

  2. #2
    Registered User
    Join Date
    10-11-2011
    Location
    FB Republic
    MS-Off Ver
    2016
    Posts
    36

    Re: Insert rows based on user input from cell value in other sheet

    hi.
    try this with a copy of your file. save as your file xlsm.

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    10-30-2011
    Location
    Southeastern USA
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Insert rows based on user input from cell value in other sheet

    That is perfect, except that it doesn't automatically update the rows if I change the input value. Do I have to use a button to launch it or is there a way to make it update dynamically? I'll see if I can find an answer before you or anyone else posts back.

    Thank you very much!


    EDIT: Nevermind, the button launch will work fine for this application. Thanks again for your quick help!
    Last edited by MrPisky; 10-30-2011 at 08:48 PM.

  4. #4
    Registered User
    Join Date
    10-30-2011
    Location
    Southeastern USA
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Insert rows based on user input from cell value in other sheet

    Perhaps this is an oversight on my part in explaining what I was looking for, but the macro does not remove any rows, it only inserts new rows every time it is run. I probably should have sad that I needed the macro to adjust number of new rows between the initial date lines up or down depending on the value set by the user.

    However, I think I can live with having it just add new rows if I could also put in a second "Delete" macro to function the same way, using that same input value. It just needs to not delete my original dated rows and just the ones in between them.

    Also, I'm now noticing some other unexpected behavior. The first time I ran it with "1" as the input value, it worked perfectly. But if I re-run the macro with the same input value of "1", then each successive time it runs, it add rows exponentially. The first time it added "1". Next time, it added "2", and the next "7", and so on. Yet, the input value remained "1". What is wrong?
    Last edited by MrPisky; 10-30-2011 at 09:43 PM.

  5. #5
    Registered User
    Join Date
    10-30-2011
    Location
    Southeastern USA
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Insert rows based on user input from cell value in other sheet

    When there is only one row to start with...it works as expected on each run, adding only one new row each time. But as soon as you start with two dated rows, it begins to add rows exponentially.

  6. #6
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Insert rows based on user input from cell value in other sheet

    Maybe better to hide rows instead of delete/insert them?
    See an example in the file.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    10-30-2011
    Location
    Southeastern USA
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Insert rows based on user input from cell value in other sheet

    Quote Originally Posted by nilem View Post
    Maybe better to hide rows instead of delete/insert them?
    See an example in the file.
    That turned out to be a very good suggestion. It works very well and is probably a better fit for my project than delete/insert. My thanks to both you and mancubus for your kind assistance in taking the time to help me solve this, it is much appreciated!
    Last edited by MrPisky; 10-31-2011 at 09:02 PM.

  8. #8
    Forum Expert ConneXionLost's Avatar
    Join Date
    03-11-2009
    Location
    Victoria, Canada
    MS-Off Ver
    2010
    Posts
    2,952

    Re: Insert rows based on user input from cell value in other sheet

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save
    Would you like to say thanks? Please click the: " Add Reputation" button, on the grey bar below the post.

  9. #9
    Registered User
    Join Date
    10-30-2011
    Location
    Southeastern USA
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Insert rows based on user input from cell value in other sheet

    Quote Originally Posted by ConneXionLost View Post
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Done, thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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