Sub HighlightTodayAndTomorrow() Dim todayDate As Date Dim tomorrowDate As Date Dim lastRow As Long Dim i As Long todayDate = Date tomorrowDate = Date + 1 lastRow = Range("a1").CurrentRegion.Rows.Count For i = 1 To lastRow If Cells(i, 1).Value = todayDate Or Cells(i, 1).Value = tomorrowDate Then Rows(i).Interior.Color = RGB(198, 239, 206) '将符合条件的行背景色设为淡绿色 Else Rows(i).Interior.ColorIndex = xlNone '取消背景色 End If Next i End Sub將顔色修改為綫框,
时间: 2024-02-14 14:07:56 浏览: 65
好的,根据您的要求,以下是新的VBA代码:
```VBA
Sub HighlightTodayAndTomorrow()
Dim todayDate As Date
Dim tomorrowDate As Date
Dim lastRow As Long
Dim i As Long
todayDate = Date
tomorrowDate = Date + 1
lastRow = Range("a1").CurrentRegion.Rows.Count
For i = 1 To lastRow
If Cells(i, 1).Value = todayDate Or Cells(i, 1).Value = tomorrowDate Then
Rows(i).Borders.LineStyle = xlContinuous '将符合条件的行边框设为实线
Rows(i).Borders.Weight = xlThin '将符合条件的行边框粗细设为细线
Rows(i).Borders.ColorIndex = 1 '将符合条件的行边框颜色设为黑色
Else
Rows(i).Borders.LineStyle = xlNone '取消边框
End If
Next i
End Sub
```
这段代码会将当前工作表中日期等于今天或明天的行加粗边框,颜色为黑色,线型为实线,粗细为细线,但是不会改变已经有边框的行的样式。如果您需要修改颜色、线型或粗细,可以自行修改 Borders 属性中的参数。
阅读全文