How to find column with oldest date?

rizzo93

Active Member
Joined
Jan 22, 2015
Messages
303
Office Version
  1. 365
I have a row containing formulas that will either show a date or a "".

ABCDEF
6/56/46/36/2

Using VBA, I want to find the column where the oldest date is located in that row. So in the example above, I need to identify the column where 6/2 is located.

How can I do this please?
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
How about
VBA Code:
Application.min(range("A1:F1"))
 
Upvote 0
Hi Fluff and thank you!

I should have been more clear: I need to know which column that smallest value is located.
 
Upvote 0
How about
VBA Code:
   Dim fnd As Range
   Dim Mn As Long
   
   Mn = Application.min(Range("A1:F1"))
   Set fnd = Range("A1:F1").Find(CDate(Mn), , xlValues, xlWhole, , , , , False)
   MsgBox fnd.Column
 
Upvote 0
How about
VBA Code:
   Dim fnd As Range
   Dim Mn As Long
  
   Mn = Application.min(Range("A1:F1"))
   Set fnd = Range("A1:F1").Find(CDate(Mn), , xlValues, xlWhole, , , , , False)
   MsgBox fnd.Column

I tried your code with the actual range replaced with my own, but I'm getting an error:

Annotation 2020-06-08 141016.png


Also, I usually use Application.WorksheetFunction.Min but I noticed WorksheetFunction missing from your code, so is that no longer necessary? Would be useful since it's less to remember.
 
Upvote 0
Are your dates real dates?
 
Upvote 0
If by "real" you mean "m/d", then I'll answer it this way: the dates are formatted in the cells to show in the format of "m/d".
 
Upvote 0
If you change the format of the cell to general, what do you see?
 
Upvote 0

Forum statistics

Threads
1,224,788
Messages
6,180,953
Members
453,009
Latest member
lorbieckit

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