+ Reply to Thread
Results 1 to 6 of 6

Select range between blank cells

  1. #1
    Registered User
    Join Date
    05-11-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    4

    Select range between blank cells

    Hiya

    This is my first post, so I hope I don't do anything wrong. I have a column with dates, seperated randomly by empty cells. Like this:


    2004-03-03 00:00:00
    2004-03-29 00:00:00
    2004-07-27 00:00:00

    2004-03-03 00:00:00

    2004-03-03 00:00:00

    2004-11-30 00:00:00
    2004-12-06 00:00:00

    2003-09-29 00:00:00
    2004-07-19 00:00:00
    2005-03-16 00:00:00
    2005-09-27 00:00:00
    2008-06-16 00:00:00
    2010-06-11 00:00:00

    2003-10-28 00:00:00
    2003-12-03 00:00:00
    2003-12-22 00:00:00
    2004-03-03 00:00:00
    2008-06-16 00:00:00

    2003-12-03 00:00:00
    2006-04-07 00:00:00
    2006-11-02 00:00:00
    2008-06-16 00:00:00

    I need to know the earliest date within each of the "mini-ranges" seperated by the blank cells. So the first would be 2003-03-03, the second would be 2004-03-03. In the example above, the earliest dates for each is the first value, but this will not always be the case.

    It would also be useful if it could tell me how many values are in each "mini-range" . So the first would be 3, the second 1 etc

    I've been surfing google for a result, but am not having any luck. I'd really appreciate any help.

    Thanks

  2. #2
    Registered User
    Join Date
    05-11-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Select range between blank cells

    Oh yes, I don't know if it makes a difference, but I'm running Excel 2007

  3. #3
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Select range between blank cells

    zel,

    You can use the following macro to accomplish what you requested:
    Please Login or Register  to view this content.


    Notes about the macro:
    • To change which column the dates are stored in, change DateCol to the correct column letter (right now macro assumes they are in column A)
    • To change which row the dates start in, change DateRow to the correct row number (right now macro assumes the dates start in row 1)

    To add a macro to a workbook:
    1. Save a copy of the Excel workbook you want to modify
    2. Always test macros in a copy so that the original is preserved in case the modifications don't go smoothly
    3. Open the copy of the Excel workbook you want to modify
    4. Use the keyboard shortcut ALT+F11 to open the Visual Basic Editor
    5. Insert -> Module
    6. Copy/Paste the code into that area

    To run a macro in a workbook:
    1. In Excel 2007, go to the View tab in the ribbon
    2. On the far right, click Macros
    3. Double-click the desired macro (I named this one EvaluateDates)

    Hope that helps,
    ~tigeravatar

  4. #4
    Registered User
    Join Date
    05-11-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Select range between blank cells

    Hi Tigeravatar

    Thanks very much for your help. When I run the macro, it comes up with an error message: Run time error '13': Type mismatch. When I click Debug it highlights

    ElseIf aCell.Value - FirstDate < 0 Then

    Oddly, it does work with the example I posted above, but with some extract that I tried it on it ends up looking like this:

    2002-12-23 00:00:00 # of Dates: 1 Earliest Date: 23/12/2002

    2006-11-17 00:00:00 # of Dates: 1 Earliest Date: 17/11/2006

    2006-11-17 00:00:00 # of Dates: 1 Earliest Date: 17/11/2006

    2001-03-27 00:00:00 # of Dates: 1 Earliest Date: 27/03/2001

    2002-01-07 00:00:00 # of Dates: 1 Earliest Date: 07/01/2002

    2006-11-17 00:00:00 # of Dates: 1 Earliest Date: 17/11/2006

    2001-03-15 00:00:00
    2010-06-11 00:00:00

    2001-03-15 00:00:00

    2001-03-15 00:00:00

    2006-11-17 00:00:00

    2001-03-27 00:00:00

    like it worked fine at first and then decided to just stop running at some point, and

    2001-02-15 00:00:00 # of Dates: 1 Earliest Date: 15/02/2001

    2002-01-17 00:00:00 # of Dates: 1 Earliest Date: 17/01/2002

    2008-10-27 00:00:00 # of Dates: 1 Earliest Date: 27/10/2008

    2008-09-11 00:00:00 # of Dates: 1 Earliest Date: 11/09/2008

    2002-02-28 00:00:00 # of Dates: 1 Earliest Date: 28/02/2002

    2002-05-23 00:00:00 # of Dates: 1 Earliest Date: 23/05/2002

    2004-07-07 00:00:00 # of Dates: 1 Earliest Date: 07/07/2004

    2004-06-30 00:00:00 # of Dates: 2 Earliest Date: 20/12/2001

    2001-12-20 00:00:00
    2006-11-17 00:00:00

    where it mixed up the last two ranges.

    There were also a few short examples where it seemed to work just fine.

    I can rearrange the data to look like this if it makes any difference

    ENT0100-0487
    2002-09-11 00:00:00
    ENT0100-0489
    2003-02-19 00:00:00
    2005-04-28 00:00:00
    ENT0100-0493
    2002-07-30 00:00:00
    ENT0100-0496
    2005-10-03 00:00:00
    ENT0100-0500
    2002-07-17 00:00:00
    ENT0100-0518
    2001-07-18 00:00:00
    2010-07-30 00:00:00
    2010-08-10 00:00:00
    ENT0100-0519
    2001-07-25 00:00:00
    2010-08-10 00:00:00


    Aaaargghhh, I can't get the post to show the data as it is in the worksheet. The ENTxxxx-xxxx starts in A1 and the date in B2. I'l attach a sample.



    Any ideas?

    zel
    Attached Files Attached Files
    Last edited by zel; 05-12-2011 at 04:50 AM.

  5. #5
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Select range between blank cells

    zel,

    you sample workbook had the dates, but they were text for some reason and not dates. That's what was causing the mismatch. I included in the code to format them as general and then reput the dates in so that they Excel would read them as dates. It worked successfully after that.

    Updated code:
    Please Login or Register  to view this content.


    Hope that helps,
    ~tigeravatar

  6. #6
    Registered User
    Join Date
    05-11-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Select range between blank cells

    That worked perfectly. Thank you, thank you. I've been bashing my head against this one for weeks.

+ 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