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

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

onlyadrafter

Well-known Member
Joined
Aug 19, 2003
Messages
5,703
Platform
  1. Windows
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.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,332
Messages
5,769,470
Members
425,552
Latest member
learnerrr

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
Top