我设置了以下VBA,以便当我更改A9的值时,它会更改日历中的月份,而A10会更改位置-它几乎完美地突出显示了为每个日期选择的日期,但是如果取消了日期,则会突出显示红色,如果随后预订,则不会突出显示黄色。有什么想法吗?
https://ibb.co/HzFvQ5P-显示日历设置。
If Not Intersect(Target, Range("A9")) Is Nothing Or Not Intersect(Target, Range("A10")) Is Nothing Then
Dim cell As Range
Dim mrng As Range
Dim loc As Range
Dim rcount As Long
Set mrng = Range("B9:H14")
Set loc = Range("A10")
rcount = Cells(2, "N").End(xlDown).Row
mrng.Interior.Color = xlNone
mrng.Borders.LineStyle = Excel.XlLineStyle.xlLineStyleNone
For Each cell In mrng
For x = 2 To rcount
If Cells(x, "T") = loc And Cells(x, "J") = "CONFIRMED" And cell >= Cells(x, "N") And cell <= Cells(x, "O") Then
cell.Interior.Color = vbYellow
End If
If Cells(x, "T") = loc And Cells(x, "J") = "PROV" And cell >= Cells(x, "N") And cell <= Cells(x, "O") Then
cell.Interior.Color = vbGreen
End If
If Cells(x, "T") = loc And Cells(x, "J") = "CANCELLED" And cell >= Cells(x, "N") And cell <= Cells(x, "O") Then
cell.Interior.Color = vbRed
End If
Next x
If cell = Date Then cell.BorderAround ColorIndex:=5, Weight:=xlMedium
Next cell
End If
End Sub