+ Reply to Thread
Results 1 to 5 of 5

How to insert a row and fill in missing data with macro

  1. #1
    Registered User
    Join Date
    03-07-2010
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2003
    Posts
    4

    Exclamation How to insert a row and fill in missing data with macro

    Hello forum!

    I am working with a really large excel file and I could really need som help with writing a code for a macro! My file looks like that:

    Row B C D
    1 1 45 F
    2 3 33 M
    3 5 37 M
    4 9 87 F
    5 15 67 F

    where column B = patient's number, C=age, D=*** etc
    What I want to do is insert a blank row for every patient missing (like number 2, 4, 6, 7 etc) so it looks like this:

    Row B C D
    1 1 45 F
    2 2
    3 3 33 M
    4 4
    5 5 37 M

    I would like to fill in only Column B with the missing numbers but the other columns will be left blank.

    If you could provide me with the right code for a macro I would be really, really greatful.
    Thank you!!!

    Catherine7

  2. #2
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: How to insert a row and fill in missing data with macro

    non macro
    in the first cell at end of your data with gaps
    say its column a and last used cell is a1000
    in a1001 put
    =IF(COUNTIF($A$2:$A$1000,ROWS($A$1:A1))=0,ROWS($A$1:A1),"")
    drag down untill last number catered for
    copy past special values and sort
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  3. #3
    Registered User
    Join Date
    03-07-2010
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: How to insert a row and fill in missing data with macro

    Thank you Martin for your quick reply!
    I tried that and it doesn't work! Is there any other way to insert rows and fill missing entries in a series?
    Many, many thanks

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: How to insert a row and fill in missing data with macro

    Hi Catherine7

    If you would post a sample workbook that shows what you have (before) on one sheet and a sheet of what you wish it to be (after), I'll be glad to look at the issue with you.

    John
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  5. #5
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: How to insert a row and fill in missing data with macro

    Somehow it seems you have posted this twice...

    Does this not answer your question...

    http://www.excelforum.com/excel-prog...-a-series.html

+ 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