如何从列中的日期列表中找到最早的日期?

时间:2015-05-01 13:31:47

标签: excel vba date

我已经使用现有代码并尝试将其调整为我想要做的事情,但是我在这个过程中遇到了麻烦。

我将处理的每个Excel工作表中的列大小(日期数)会有所不同。每个单元格将以def格式包含dd / mm / yyyy格式的日期。

运行时错误' 13' 类型不匹配

知道如何解决这个问题吗?

Dim j As Integer, minValue As Date
Dim t0 As Double, t1 As Double
Dim ans As Date

t0 = CDbl(DateSerial(2000, 1, 1))
t1 = CDbl(DateSerial(2100, 12, 31))
ans = 0
For j = 3 To 7
    If ans = 0 Then ' You need to store the first valid value
        If Sheets(1).Cells(j, 9).Value >= t0 And Sheets(1).Cells(j, 9) <= t1 Then
            ans = Sheets(1).Cells(j, 9).Value
        End If
    Else
        If (Sheets(1).Cells(j, 9).Value >= t0 And Sheets(1).Cells(j, 9) <= t1) _
           And Sheets(1).Cells.Value < ans Then
            ans = Sheets(1).Cells(j, 9).Value
        End If
    End If
Next j

1 个答案:

答案 0 :(得分:0)

这是一种更直接的方法:

[sheet2!a1] = cdate([small(sheet1!i:i,1)])
相关问题