+ Reply to Thread
Results 1 to 11 of 11

Insert New Rows Between Existing Cells With Missing Sequential Dates

  1. #1
    Registered User
    Join Date
    11-08-2014
    Location
    Malaysia
    MS-Off Ver
    2010
    Posts
    84

    Question Insert New Rows Between Existing Cells With Missing Sequential Dates

    Hello members,
    I've read all answers about the thread in this page before opening a new thread, but ... .

    I'd like to have the code insert rows where the dates are missing and assign "?" to them in column C (Value).
    Could you please do consider all issues.

    1. Datasets are in daily format and the duration is not fixed but sequential ascending. (e.g. 1/1/1949 - 30/12/2010)
    2. In a Msg Box, shows the number of inserted rows.
    3. Values start from 3rd row and col B&C have different values.
    11-22-2014 9-03-17 PM.png
    Regards,

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,419

    Re: Insert New Rows Between Existing Cells With Missing Sequential Dates

    Your example shows 1/1/1948 but your description says the dates start at 1/1/1949.

    Am I right in thinking you need a row for every date from the 1/1/1948 through to 30/12/2010 and that you have data for some, if not the majority, of those dates?

    I suspect that testing all the dates for gaps and inserting rows could be a slow process. I'd suggest filling in all the dates, in another column, perhaps on another sheet, and then matching them to the information you have.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    11-08-2014
    Location
    Malaysia
    MS-Off Ver
    2010
    Posts
    84

    Re: Insert New Rows Between Existing Cells With Missing Sequential Dates

    Quote Originally Posted by TMS View Post
    Your example shows 1/1/1948 but your description says the dates start at 1/1/1949.
    Thank you TMS. I have many files and I just wanted to show an example about my data. I can upload a sample csv file, if needed.
    The main point is, my data does not have a fix duration and start date & end date are different in each file.

    The solution that you said would be nice if I had few files. But, I have 1000+ files and I'd rather a more automated process, if possible please.
    11_22_2014_11_11_59_PM.png
    Last edited by Moriexcel; 11-22-2014 at 11:40 AM.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,419

    Re: Insert New Rows Between Existing Cells With Missing Sequential Dates

    OK, so the files are .csv (text) files, not Excel files? And you have 1000+ files in the same folder/location? Each one may have a different start and end date, but the same file structure?

    Do you want to end up with .csv files or Excel files?

    Please post a sample .csv file.

    Regards, TMS

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,419

    Re: Insert New Rows Between Existing Cells With Missing Sequential Dates

    OK, so I see you have another thread running that will open and process the 1000+ .csv files. So you just need code to fill the date gaps?

    http://www.excelforum.com/excel-prog...ple-files.html


    Regards, TMS

  6. #6
    Registered User
    Join Date
    11-08-2014
    Location
    Malaysia
    MS-Off Ver
    2010
    Posts
    84

    Re: Insert New Rows Between Existing Cells With Missing Sequential Dates

    Quote Originally Posted by TMS View Post
    OK, so I see you have another thread running that will open and process the 1000+ .csv files. So you just need code to fill the date gaps?

    http://www.excelforum.com/excel-prog...ple-files.html


    Regards, TMS
    Yes. Exactly. The files have same structure and some of them have gaps between.
    I need to run this code to fill the gaps first, and then run that macro
    I attached the sample file. Year 1980 is missing here for example.
    Could you please assign "?" in Column C (Value) for inserted rows?

    Regards, Mori
    Attached Files Attached Files

  7. #7
    Valued Forum Contributor
    Join Date
    03-21-2013
    Location
    cyberia
    MS-Off Ver
    Excel 2007
    Posts
    457

    Re: Insert New Rows Between Existing Cells With Missing Sequential Dates

    Like this?
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    11-08-2014
    Location
    Malaysia
    MS-Off Ver
    2010
    Posts
    84

    Re: Insert New Rows Between Existing Cells With Missing Sequential Dates

    Thank you. Yes. But it shows "Run Time Error: '13'. Type mismatch" in Ln 6.
    Do I have to change something in the code?

  9. #9
    Valued Forum Contributor
    Join Date
    03-21-2013
    Location
    cyberia
    MS-Off Ver
    Excel 2007
    Posts
    457

    Re: Insert New Rows Between Existing Cells With Missing Sequential Dates

    That error will occur if the data you posted in your sample file are different from those data giving you the error.
    I tested that code on your data as you posted and it worked just fine.
    It does require your "dates" are numbers (even if formatted differently) otherwise that code will error and the concept of what is "sequential" and hence the meaning of your question becomes rather blurred.

    Here's a minor variation of the code that doesn't require data input in colA from A3 downward to be integers. It shouldn't give the same error, but since I don't know the specific structure of your data I consequently can't be sure this code will give the result you want either.
    Please Login or Register  to view this content.
    Apposite to my original code, you might check that, if you reformat ColumnA as "general", then do all of your "dates" then appear as positive integers from about 28,000 to 40,000?

  10. #10
    Registered User
    Join Date
    11-08-2014
    Location
    Malaysia
    MS-Off Ver
    2010
    Posts
    84

    Re: Insert New Rows Between Existing Cells With Missing Sequential Dates

    Yes. Thank you it works.I already approve your post.
    But, I have a big problem with my datasets that gives me a headache and I can not easily use the code helped by others like you.
    I am going to use your code after running this code to change the cell format to DMY.
    Please Login or Register  to view this content.
    Because my csv files have a crazy format in MY LAPTOP !! And I don't know why !
    123.png
    Attached Images Attached Images
    Last edited by Moriexcel; 11-24-2014 at 11:17 AM.

  11. #11
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,419

    Re: Insert New Rows Between Existing Cells With Missing Sequential Dates

    You could just select the column of dates and use Text to Columns to convert the text "dates" to true dates. You'd need to select the date format as MDY.

    Regards, TMS

+ 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. Spacing between missing sequential dates
    By kgust003 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-12-2014, 01:09 PM
  2. Insert cells below existing rows
    By REFisher14 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-01-2013, 01:17 PM
  3. Excel Macro to find missing dates and insert missing date as blank row
    By JevaMarie in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-26-2013, 11:08 AM
  4. Insert new rows between existing cells with missing sequential dates
    By madball87 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-09-2011, 11:06 AM
  5. Insert rows for missing dates
    By areeves1980 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-06-2009, 10:59 AM

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