我正在使用一个非常简单的 VBA 代码来识别日期之间的句点,但是当我运行宏时,Excel 似乎没有将单元格识别为日期并生成类型不匹配错误,你能帮忙解决这个问题吗?提前谢谢了。
Sub datesexcelvba()
Dim mydate1 As Date
Dim mydate2 As Long
Dim datetoday1 As Date
Dim datetoday2 As Long
Dim x As Long
lastrow = Sheets("sheet1").Cells(Rows.Count, 1).End(xlUp).Row
For x = 8 To lastrow
mydate1 = Cells(x, 10).Value
mydate2 = mydate1
Cells(x, 25).Value = mydate2
datetoday1 = Date
datetoday2 = datetoday1
Cells(x, 20).Value = datetoday2
If mydate2 - datetoday2 = 3 Then
Cells(x, 29) = "yes"
Cells(x, 29).Interior.ColorIndex = 3
Cells(x, 29).Font.ColorIndex = 2
Cells(x, 29).Font.Bold = True
Cells(x, 30).Value = mydate2 - datetoday2
End If
Next
End Sub