+ Reply to Thread
Results 1 to 5 of 5

Find range of rows containing values between two dates when start date may be missing

Hybrid View

  1. #1
    Registered User
    Join Date
    06-14-2010
    Location
    Kuala Lumpur
    MS-Off Ver
    Excel 2007
    Posts
    8

    Find range of rows containing values between two dates when start date may be missing

    I am trying to select a range of rows based on date values which are in one column, the dates are ascending but are repetitive and some dates may be missing. e.g.
    11/Jun
    11/Jun
    11/Jun
    12/Jun
    12/Jun
    14/Jun
    14/Jun
    14/Jun
    14/Jun
    15/Jun
    15/Jun
    16/Jun
    16/Jun
    16/Jun
    17/Jun

    What I want to do is specify a date range e.g 10/Jun to 13/Jun and find the starting row and ending row of the range containing all data related to these dates. (In my database sheet the adjacent columns to the dates contain production information)

    Is there any way I can specifiy the date range as 10/Jun to 13/Jun and (given that these two dates are missing) then identify the 1st row as being the first date higher than 10/Jun and the last row as being the last occurrence of a date less than 13/Jun.

    The idea is to be able to specify any period, then identify the range of rows containing all the values between the two dates as quckly as and then use arrays to to transfer the selected datarange from the 'database' sheet to a report sheet.

    If I can get the range of rows I can quickly copy the data to an array and then write the array to the new range. I have tried all sorts of Match, Index/Match, Lookup type formulae to try and get the start and and rows based on the specified dates but as soon as one of the dates is missing this results in a formula error #N/A.

    It is part of a report generating spreadsheet which gets production for each day during the production period and lists the production statistics, there are multiple entries per day when production is in progress but there may be missing dates due to no production. I have been able to achieve a workaround solution to the problem by reading each row of the data list one row at a time with a loop and then a conditional statement to select only those rows that containing dates falling between the given values and writing them to a new range of rows but this results in a very slow read/write operation.

    The missing dates are giving me a real headache but cannot be avoided, once I can identify the extents of the data range I can use much faster arrays to transfer the data from the 'database' sheet to the report sheet.

    Many thanks
    Jon

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: Find range of rows containing values between two dates when start date may be missing

    Use Two Input box to store the Start and End dates in a Date variables.

    Then just apply Auto Filter on the DateData and use GreaterThanOrEqualTo (Start Date) and LessThanOREqualTo (EndDate) in Filter criteria so that the Auto Filter will filter those matching dates. Just simply select the visible cells and copy the dates and paste it in your report sheet.


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  3. #3
    Registered User
    Join Date
    06-14-2010
    Location
    Kuala Lumpur
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Find range of rows containing values between two dates when start date may be missing

    I am not sure how to do this within a VBA macro.

    The whole routine is generating a 7-day period report based on the date entered in one cell. On entering the date the macro will generate a report containing all the necessary production statistics for the 7 days preceding the entered date, the rows of production data I am trying to identify are just one part of a more comprehensive report.

    Rgds,
    Jon

  4. #4
    Registered User
    Join Date
    10-19-2013
    Location
    England
    MS-Off Ver
    Excel 2007/2010
    Posts
    10

    Arrow Re: Find range of rows containing values between two dates when start date may be missing

    I'm going to be doing something similar albeit searching a column in an external worksheet; came across this thread while doing a little research!
    Basic points are that: always ascending, always a date value, the exact start and end search date may not be present.
    So far, my thoughts are:
    - I just need the start and end of the range. (So do you, only calculated by the fixed 7-day offset)
    - Likely a lot of records to search, so could make for a rather large array. May as well work from sheet.
    - Date as a (serial) number (double) is easier to work with. (Strip out time if needed)
    - Loops are slow, but .find is ten times faster, so I could afford to .find a date: On fail; (de)increment by a day and .find again until result or other extreme. Could run concurrently until both ends meet in the middle!

    Alternatively; just drop a formula for the range into a spare cell and take the result:
    MATCH for anything greater than end / lesser than start to eliminate.

    I was expecting analysis like this to be a pretty common requirement, but haven't found much, so I'll build my own!
    Last edited by Googlyhead; 10-19-2013 at 01:58 AM. Reason: Clarity.

  5. #5
    Registered User
    Join Date
    06-14-2010
    Location
    Kuala Lumpur
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Find range of rows containing values between two dates when start date may be missing

    You have the problem in a nutshell, it is much faster to read and write by reading data to an array in memory so I think that my solution will be this,

    1) Find the last valid row of the database
    2) Select the whole database range - in this case Range("A3:O" & LastRow)
    2) Read the whole database into an array (it will be a couple of hundred rows and 15 columns)
    3) Search the first element of each record (essentially the column A dates) for all values which are => than 'Date1' and <= 'Date2' and output those records to another array.
    4) Read from the output array and write to the report page.

    Have only got to test point so far but it reads and writes much faster than using do and copying each relevant row from the database to the report by using loops and range copying.

    Writing to and Reading from an array in memory is fast and data looping through the array to select the data within the date-range is very quick so I do not need to find the start and end 'rows' first.

    Will see how I get on but looks promising so far.

    Cheers
    Jon

+ 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. 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
  2. Find the start and end date of range of consecutive dates.
    By aguirre.m36 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-25-2013, 09:24 PM
  3. Date Range - Start and End Date - Identify dates in a quarter
    By Nikki Fox in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-12-2012, 06:05 AM
  4. Replies: 2
    Last Post: 01-04-2012, 09:15 AM
  5. Replies: 8
    Last Post: 02-27-2009, 06:06 PM

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