How to find column with oldest date?

rizzo93

Board Regular
Joined
Jan 22, 2015
Messages
246
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?
 

Some videos you may like

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
42,912
Office Version
365
Platform
Windows
How about
VBA Code:
Application.min(range("A1:F1"))
 

rizzo93

Board Regular
Joined
Jan 22, 2015
Messages
246
Hi Fluff and thank you!

I should have been more clear: I need to know which column that smallest value is located.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
42,912
Office Version
365
Platform
Windows
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
 

rizzo93

Board Regular
Joined
Jan 22, 2015
Messages
246
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.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
42,912
Office Version
365
Platform
Windows
Are your dates real dates?
 

rizzo93

Board Regular
Joined
Jan 22, 2015
Messages
246
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".
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
42,912
Office Version
365
Platform
Windows
If you change the format of the cell to general, what do you see?
 

rizzo93

Board Regular
Joined
Jan 22, 2015
Messages
246
Or maybe "serial" isn't the right term. I'm seeing the number 43986.
 

Watch MrExcel Video

Forum statistics

Threads
1,102,818
Messages
5,489,041
Members
407,668
Latest member
MODELXLS

This Week's Hot Topics

  • Timer in VBA - Stop, Start, Pause and Reset
    [CODE=vba][/CODE] Option Explicit Dim CmdStop As Boolean Dim Paused As Boolean Dim Start Dim TimerValue As Date Dim pausedTime As Date Sub...
  • how to updates multiple rows in muliselect listbox
    Hello everyone. I need help with below code. code is only chaning 1st row in mulitiselect list box. i know issue with code...
  • Delete Row from Table
    I am trying to delete a row from a table using VBA using a named range to find what I need to delete. My Range is finding the right cell. In the...
  • Assigning to a variable
    I have a for each block where I want to assign the value in column 5 of the found row to the variable Serv. [CODE=vba] For Each ws In...
  • Way to verify information
    Hi All, I don't know what to call this formula, and therefore can't search. I have a spreadsheet with information I want to reference...
  • Active Cell Address – Inactive Sheet
    How to use VBA to get the cell address of the active cell in an inactive worksheet and then place that cell address in a location on the current...
Top