什麼代碼的作用是,如果上校X和Y包含日期整行,顏色全行作爲黃色。
如果只有X包含日期,則將整行着色爲紅色。
但是,如果X和Y爲空,則將其變爲綠色。在最後的條件。
如果滿足條件,我不能讓我的代碼在整行上着色。
Dim i As Long
Dim lrX As Long 'last row with a filled cell in column X
Dim lrY As Long 'last row with a filled cell in column Y
Dim lr As Long 'max of lrX and lrY
Dim ws As Worksheet
Set ws = ActiveSheet
lrX = Range("X" & Rows.Count).End(xlUp).Row
lrY = Range("Y" & Rows.Count).End(xlUp).Row
lr = Application.WorksheetFunction.Max(lrX, lrY)
For i = 2 To lr 'my data starts in row 1, otherwise change this
If IsDate(ws.Range("X" & i).Value) Then
If IsDate(ws.Range("Y" & i).Value) Then
ws.Range("a" & i).EntireRow.Interior.Color = vbYellow 'both X and Y have a date value, so Yellow
Else
ws.Range("a" & i).EntireRow.Interior.Color = vbRed 'only X has a date
If (.Cells(i, 24).Value = "") And _
(.Cells(i, 25).Value = "") Then
.Rows(i).EntireRow.Interior.ColorIndex = 4 ' 4: Green
End If
End If
Next i
謝謝Michael! – jackie