Microsoft provides programming examples for illustration only, without warranty either
expressed or implied, including, but not limited to, the implied warranties of
merchantability and/or fitness for a particular purpose. This article assumes
that you are familiar with the programming language being demonstrated and the
tools used to create and debug procedures. Microsoft support professionals can
help explain the functionality of a particular procedure, but they will not
modify these examples to provide added functionality or construct procedures to
meet your specific needs. If you have limited programming experience, you may
want to contact a Microsoft Certified Partner or the Microsoft fee-based
consulting line at (800) 936-5200. For more information about Microsoft Certified
Partners, please visit the following Microsoft Web site:
For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:
The example below demonstrates the use of the
Min and
Max functions against arrays. When the
Min and
Max functions are applied to the entire array of the Date data type, they return zero. However, when they are applied to the individual elements of the array the correct values are returned.
If you want to apply the
Min and
Max functions to the entire array you must use the Double data type, as demonstrated in the last part of the code.
NOTE: Microsoft Excel stores dates as serial numbers calculated as the number of days since January 01, 1900. The sample code in this article displays dates as serial numbers.
Sample Visual Basic Procedure
Sub DateArrayTest()
Dim dtarr(1 To 2) As Date
Sheets("sheet1").Activate
dtarr(1) = "1963-01-17"
dtarr(2) = "1996-05-08"
ActiveSheet.Cells(1, 2).Value = "Entire Array"
ActiveSheet.Cells(1, 3).Value = "Individual Elements"
ActiveSheet.Cells(1, 4).Value = "Double"
ActiveSheet.Cells(2, 1).Value = "Min"
ActiveSheet.Cells(3, 1).Value = "Max"
'Evaluate the entire array - result is 0
ActiveSheet.Cells(2, 2).Value = Application.Min(dtarr)
ActiveSheet.Cells(3, 2).Value = Application.Max(dtarr)
'Evaluate individual elements of array - correct result
ActiveSheet.Cells(2, 3).Value = Application.Min(dtarr(1), dtarr(2))
ActiveSheet.Cells(3, 3).Value = Application.Max(dtarr(1), dtarr(2))
Dim dblarr(1 To 2) As Double
'Initialize the array
dblarr(1) = dtarr(1)
dblarr(2) = dtarr(2)
'Evaluate the Double datatype array - correct result
ActiveSheet.Cells(2, 4).Value = Application.Min(dblarr)
ActiveSheet.Cells(3, 4).Value = Application.Max(dblarr)
End Sub