Excel 宏日期格式

Excel 宏日期格式

我有一张 Excel 表,如果运行宏,它会将当前日期和时间放入特定单元格中。它将日期和时间格式化为 dd-mm-yyyy HH:mm 格式。整个三月,这都运行正常。但是,现在到了四月,它突然将日期输出为 mm-dd-yyyy HH:mm。

造成这种情况的原因是什么?

这是代码:

Sub Test()
Dim i As Long


For i = 1 To Cells(Rows.Count, "A").End(xlUp).Row
Status = Cells(i, 1).Value

If Status = "Status1" And IsEmpty(Cells(i, 12).Value) = True Then
Cells(i, 12).Value = Format(Now, "dd-mm-yy HH:mm")

ElseIf Status = "Status2" And IsEmpty(Cells(i, 13).Value) = True Then
Cells(i, 13).Value = Format(Now, "dd-mm-yy HH:mm")

ElseIf Status = "Status3" And IsEmpty(Cells(i, 14).Value) = True Then
Cells(i, 14).Value = Format(Now, "dd-mm-yy HH:mm")

ElseIf Status = "Status4" And IsEmpty(Cells(i, 15).Value) = True Then
Cells(i, 15).Value = Format(Now, "dd-mm-yy HH:mm")

ElseIf Status = "Status5 " And IsEmpty(Cells(i, 16).Value) = True Then
Cells(i, 16).Value = Format(Now, "dd-mm-yy HH:mm")

ElseIf Status = "Status6" And IsEmpty(Cells(i, 17).Value) = True Then
Cells(i, 17).Value = Format(Now, "dd-mm-yy HH:mm")

ElseIf Status = "Status7" Then
Cells(i, 18).Value = Format(Now, "dd-mm-yy HH:mm")

End If
Next i
Application.ScreenUpdating = False
End Sub

相关内容