如何16.06.2016大于29.10.2016

我有一个macros来填补date背景,如果他们不是今天的转发。 它很好地工作,但是,只是在一个页面中,DateValues不能正确比较。 我试图用MessageBoxes显示结果,它说16.06.2016大于29.10.2016

我的macros:

Sub DolguRenkleri(ByVal StartIndex As Integer, ByVal EndIndex As Integer) Dim Tarih As String Dim Formul As String Dim Formul2 As String Tarih = Left(Now, 10) For i = StartIndex To EndIndex - 1 MsgBox (Cells(i, 2).Value > DateValue(Tarih)) If Cells(i, 2) <= DateValue(Tarih) Then With Range("A" + CStr(i), "H" + CStr(i)) .Interior.ColorIndex = 6 End With Formul = "=TOPLA(D" + CStr(i + 1) + ":D" + CStr(EndIndex - 1) + ")" Formul2 = "=F6-A" + CStr(i) Else: With Range("A" + CStr(i), "H" + CStr(i)) .Interior.ColorIndex = 2 End With End If Next i Range("F1").FormulaLocal = Formul Range("F7").FormulaLocal = Formul2 End Sub 

它必须是单元格B10中的“16.06.2016”string不会被识别为一个真正的Date值,尽pipe您可能已select该单元格并为其指定一个“date”格式

在这种情况下,使用

 If DateValue(Replace(Cells(i, 2).Value, ".", "/")) <= DateValue(Tarih) Then