+ Reply to Thread
Results 1 to 12 of 12

automatically insert row

  1. #1
    Registered User
    Join Date
    11-05-2009
    Location
    NC
    MS-Off Ver
    Excel 2003
    Posts
    6

    automatically insert row

    Hello forum, I have a huge problem with Excel and I have no idea how to solve it. Hmm, how do I explain this? Someone is giving me data pulled from a server in an Excel format. I have a column that has a series of entries. For example:

    Blank
    Entry 1
    Entry 2
    Entry 3
    Entry 4
    Entry 5

    However, sometimes there's an entry or two missing. So it'll look like this:

    Blank
    Entry 1
    Entry 2
    Entry 4
    Entry 5

    Is there anyway to tell Excel to say "Hey there's an entry missing here," and have it insert a row with the missing entry value? I do not work in Excel ever but people around here do, in case someone has some advice. I already asked the guy if he could just server me the data formatted correctly, and -- of course -- he can't/won't. Thanks in advanced!!
    Last edited by fishnfrogs; 11-05-2009 at 06:04 PM. Reason: asked

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: automatically insert row

    Is the data as simple as that -- a single word followed by a single number?
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    11-05-2009
    Location
    NC
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: automatically insert row

    Hi, it's more complicated than that -- I believe. I have every state in one column, then it has the group column that I'm having problems with. Then is one more column with a letter in it. After that there are a few more columns that have the actually data in them. So it really looks like this:

    Alaska BLANK A 75 more data columns etc
    Alaska GROUP01 A 74 more data columns etc
    Alaska GROUP02 A 74 more data columns etc

    I'm attaching a worksheet that might help explain my situation a little better. I pretty much need it to look at the 'Group' column and determine that there is a value missing and insert a row. If it could even fill in the values of the other columns that would be amazing. Thanks for your help!!
    Attached Files Attached Files

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: automatically insert row

    Again -- is the data in column B as simple as that? Or exactly like that: GROUP followed by a 2-digit number?

  5. #5
    Registered User
    Join Date
    11-05-2009
    Location
    NC
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: automatically insert row

    It's just like GROUPXX.

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: automatically insert row

    Try this:
    Please Login or Register  to view this content.
    Adding a Macro to a Code Module
    1. Copy the code from the post
    2. Press Alt+F11 to open the Visual Basic Editor (VBE)
    3. From the menu bar in the VBE window, do Insert > Module
    4. Paste the code in the window that opens
    5. Close the VBE to return to Excel

    Running a Macro
    1. Do Alt+F8 to open the macro dialog
    2. Select the macro name (here, GroupXX) from the dropdown list and press Run

  7. #7
    Registered User
    Join Date
    11-05-2009
    Location
    NC
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: automatically insert row

    Hi, thanks for that. It's mostly working now. However, can you think of a way to insert the rows after a cell in the column is blank and the next cell value is GROUP03? If not, I can live with this. You're a life saver. Thanks!!

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: automatically insert row

    Maybe if you post before and after examples, showing (in the after example) the inserted rows highlighted.

  9. #9
    Registered User
    Join Date
    11-05-2009
    Location
    NC
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: automatically insert row

    Hmm...I haven't been able to figure anything out. Well, actually, your code worked perfectly. However, maybe to make things simpler, would you know of a way to insert a new row after a blank row and if the next row isn't GROUP00. That way I could run that script, then the script you gave me, and it should fill in all the missing values for me. I've tried using this:

    Please Login or Register  to view this content.
    But it inserts the row above the blank one. I wanted it to go below. Any suggestions are appreciated. Thanks again!!

  10. #10
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: automatically insert row

    Please provide before and after examples of what you want.

  11. #11
    Registered User
    Join Date
    11-05-2009
    Location
    NC
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: automatically insert row

    Hi, here are the examples. Thanks!!
    Attached Files Attached Files

  12. #12
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: automatically insert row

    Hello fishnfrogs,

    Here is another macro to add in the missing rows with the group and sequence numbers. I have run this on the data you posted and it works. Let me know if I missed anything. This is little more complex than Shg's code, so I haven't added comments to explain what is happening. The complexity makes it a little more difficult to understand, but also provides a lot of flexibility in string manipulation.

    I see from your profile you're a Tar Heel. I grew up in in the western side of the state in Asheville. Where are you?

    Macro Code
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

+ 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