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 = xlThick '将符合条件的行边框粗细设为粗线 Rows(i).Borders.Color = RGB(255, 0, 0) '将符合条件的行边框颜色设为红色 Else Rows(i).Borders.LineStyle = xlNone '取消边框 End If Next i End Sub修改為紅色的邊框
时间: 2024-03-03 10:49:05 浏览: 126
好的,根据您的要求,以下是修改后的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 = xlThick '将符合条件的行边框粗细设为粗线
Rows(i).Borders.Color = RGB(255, 0, 0) '将符合条件的行边框颜色设为红色
Else
Rows(i).Borders.LineStyle = xlNone '取消边框
End If
Next i
End Sub
```
如果您需要修改边框颜色,请将这行代码:
```VBA
Rows(i).Borders.Color = RGB(255, 0, 0) '将符合条件的行边框颜色设为红色
```
中的 RGB(255, 0, 0) 参数修改为其他颜色的 RGB 参数即可。
阅读全文