我想要从第4行开始更改列A和B的背景颜色,直到包含数据的行。以下代码似乎不起作用。请查看。
Sub GeneralColorForAllPopulatedCells()
Dim wb As Workbook
Dim ws As Worksheet
Dim g As Long, h As Long
Dim lastRow As Long
Dim rng As Range
Set wb = ThisWorkbook
Set ws = wb.Sheets("Sheet1")
g = ws.Range("A" & ws.Rows.Count).End(xlUp).Row
h = ws.Range("B" & ws.Rows.Count).End(xlUp).Row
If g > h Then
lastRow = g
Else
lastRow = h
End If
Set rng = ws.Range("A4:B" & lastRow)
rng.Interior.Color = RGB(204, 229, 255)
End Sub
谢谢, HEMA