VBA does not recognize values

0

I'm trying to get date-type values from a given excel cell, however, my macro does not recognize cell values even though it's filled (date). Remember that there are three sheets.

  With Worksheets("TEMP") 
    ActiveWorkbook.Sheets("TEMP").Activate
    minDate = WorksheetFunction.Min(Worksheets("TEMP").Range("F2:F65000"))
    maxDate = WorksheetFunction.Max(.Range(.Range("F2"), .Range("F65000")))
    numMonths = 1 + DateDiff("m", minDate, maxDate)
    If (numMonths < 3) Then
        countMonths = 3
    Else
        countMonths = numMonths
    End If
End With

The minDate and maxDate return as 0, just when I manually click on the cell and press Enter or click on another cell the macro recognizes, just that cell.

How to make the macro recognize that value?

    
asked by anonymous 28.01.2015 / 18:03

1 answer

1
Public Sub Teste()  
  Dim MinDate As Date
  Dim MaxDate As Date  
  MinDate = WorksheetFunction.Min(Sheets("Plan1").Range("A1:A100"))
  MaxDate = WorksheetFunction.Max(Sheets("Plan1").Range("A1:A100"))  
  Debug.Print MinDate
  Debug.Print MaxDate  
End Sub

It worked perfectly, check if the data was entered as an in-time date, if it is not, do a conversion.

    
09.02.2015 / 16:12