Find next date from todays date

ttratl

Board Regular
Joined
Dec 21, 2004
Messages
168
Hi Everyone,

I have part of a worksheet filled with unsorted dates (dd/mm/yyyy). Specifically the area is AA6:AJ200.

I need a macro that will find the next date (from today).

I've tried some code I use in another workbook, but that only searches one sorted column.

Any ideas would be great...
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
What would you want the outcome to be? The actual next date or the cell address?
 
Upvote 0
Try something like this

Sub find1()
Range("A1").Select
Do Until ActiveCell.Value = Date + 1
ActiveCell.Offset(1, 0).Select
Loop
End Sub
 
Upvote 0
http://www.rondebruin.nl/find.htm

Modified slightly

Code:
Sub Find_Next_Date()
    Dim FindString As Date
    Dim Rng As Range
    Dim i As Long
    i = 1
    
    With Sheets("Sheet1").Range("AA:AJ")
    Do Until i = 366
    FindString = CLng(Date + i)
        Set Rng = .Find(What:=FindString, _
                        After:=.Cells(.Cells.Count), _
                        LookIn:=xlFormulas, _
                        LookAt:=xlWhole, _
                        SearchOrder:=xlByRows, _
                        SearchDirection:=xlNext, _
                        MatchCase:=False)
        If Not Rng Is Nothing Then
            Application.Goto Rng, True
            Exit Sub
        Else
            i = i + 1
        End If
    Loop
    End With
End Sub

This will continue until it finds a match or there is no date within the Next Year
 
Last edited:
Upvote 0
Hi

I have defines a range called myDates as A6:J28 - change to suit your range.

This code colours any cells containing the date being searched for, but you can amend that for whatever you need to do when a date is found.

I made cell A1 hold the search date, with a formula of =TODAY()+1, but you could place that in the code if you wanted.

Code:
Sub FindNextDate()
    Dim R As Range, Found As String
    Dim searchDate As Date

    Range("myDates").Interior.ColorIndex = xlNone
    searchDate = Range("A1").Value
    With Range("mydates")
        Set R = .Find(searchDate, LookIn:=xlValues)
        If Not R Is Nothing Then
            Found = R.Address
            Do
                R.Interior.ColorIndex = 15
                Set R = .FindNext(R)
            Loop While Not R Is Nothing And R.Address <> Found
        End If
    End With
End Sub
 
Upvote 0
If you just want the date then maybe

Code:
Dim nextdate As Date
    nextdate = Evaluate("MIN(IF(AA6:AJ200>TODAY(),AA6:AJ200))")
If nextdate <= Date Then
    MsgBox "No next date found"
Else
    ' do something with nextdate
End If
 
Upvote 0
Thanks Comfy,

Just need the cell to be selected.

Thanks Trevor G,
Can't get that to work. If I change Range("A1").Select to any of the columns where my dates are it just loops continually and doesn't find any dates.
 
Upvote 0
Slight modification to my previous suggestion

Code:
Dim nextdate As Date
    nextdate = Evaluate("MIN(IF(AA6:AJ200>TODAY(),AA6:AJ200))")
If nextdate <= Date Then
    MsgBox "No next date found"
Else
    [AA6:AJ200].Find(What:=nextdate, LookIn:=xlValues, LookAt:=xlWhole).Select
End If
 
Upvote 0
Wow - thanks guys.

Comfy's code works for me. I'll check out Ron's page too.

I didn't try Roger's code as I have 4 conditional format rules colouring lots of cells and it took a while to get that to work - so I didn't want to mess that up.

Thanks everyone! 3 hours research - then come to Mr Excel and get a solution in minutes!
Love this site!
 
Upvote 0
hi

If you don't want to colour the cell then use

Code:
Sub FindNextDate()
    Dim R As Range, Found As String
    Dim searchDate As Date

    Range("myDates").Interior.ColorIndex = xlNone
    searchDate = Range("A1").Value
    With Range("mydates")
        Set R = .Find(searchDate, LookIn:=xlValues)
        If Not R Is Nothing Then
            Found = R.Address
            Do
                Msgbox ("Cell found at " & r.address)
                Set R = .FindNext(R)
            Loop While Not R Is Nothing And R.Address <> Found
        End If
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,728
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top