2015年10月3日 星期六

【Excel VBA】 日期比較,西元轉民國

today = Date
textY = Val(Year(today) - 1911)


textM = Month(today)
If (Len(textM) < 2) Then
textM = "0" + textM
End If

textD = Day(today)
If (Len(textD) < 2) Then
textD = "0" + textD
End If


i = 1


'today = CDate(textY + "/" + textM + "/" + textD)
today = CDate("103/12/31")
 MsgBox today
 MsgBox CDate(Worksheets("xxx").Range("E" & i + 1).Value)

 If (today > CDate(Worksheets("xxx").Range("E" & i + 1).Value)) Then


   MsgBox today & "> " & Worksheets("xxx").Range("E" & 1 + 1).Value

 End If


  If (today < Worksheets("xxx").Range("E" & i + 1).Value) Then


   MsgBox today & "< " & Worksheets("xxx").Range("E" & 1 + 1).Value

 End If
             

沒有留言:

張貼留言