Excel日期对比设置文本字体异常:非逾期任务被错误标红加粗
问题描述
将未完成任务录入电子表格时,希望把逾期任务设置为红色加粗字体,但现有VBA代码错误地将3条当月非逾期任务也设置成了红色加粗。推测是数据类型不匹配导致的问题,已尝试用CDate函数处理,相关代码如下:
y = 2 For x = 1 To tasks.Count Set tsk = tasks.Item(x) 'Fill in Data If Not tsk.Complete Then exWb.Sheets("Sheet1").Cells(y, 1) = tsk.DueDate exWb.Sheets("Sheet1").Cells(y, 2) = tsk.Subject If tsk.DueDate < Date Then MsgBox tsk.DueDate & " " & Date 'Make red bold exWb.Sheets("Sheet1").Cells(y, 1).Font.Bold = True exWb.Sheets("Sheet1").Cells(y, 1).Font.Color = RGB(255, 0, 0) End If exWb.Sheets("Sheet1").Cells(y, 3) = tsk.PercentComplete exWb.Sheets("Sheet1").Cells(y, 4) = tsk.Status y = y + 1 End If Next x
问题截图:表格内展示了多条任务记录,其中3条当月未逾期的任务(例如日期为“2025/5/15”的任务)被错误设置为红色加粗字体,与实际逾期任务的格式混淆。
内容的提问来源于stack exchange,提问作者Rsquest
相关产品推荐
相关产品推荐

