Max date in a row less than todays date

gazingdown

Board Regular
Joined
May 21, 2003
Messages
109
I have a row where all cells are dates. I need to be able to select the cell that has the maximum date before today.

Say I ran the report today, in my sheet there tends to be a column for each week and the date in each column tends to be a monday(but not always) and I would want to select the cell with the date 8th March 2004

This is to be done in VBA.
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Does the following code suit your needs?

Code:
Sub Macro4()
For MY_DATES = 1 To Range("IV1").End(xlToLeft).Column
    If Range("A1").Offset(0, MY_DATES - 1).Value > MY_HIGH_DATE And Range("A1").Offset(0, MY_DATES - 1).Value < (Now() - 1) Then
         MY_HIGH_DATE = Range("A1").Offset(0, MY_DATES - 1).Value
    End If
Next MY_DATES
Range("A2").Value = MY_HIGH_DATE
End Sub

The dates are in ROW A and start at 1, and the result is put in A2. You will need to adjust cell refs as required.
 
Upvote 0

Forum statistics

Threads
1,213,567
Messages
6,114,342
Members
448,570
Latest member
rik81h

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