突出显示 Column"A" <> "" 的范围
Highliting the Range Where Col"A" <> ""
我一直在尝试开发一个突出显示范围(A 到 M)的代码,其中 Col"A" <> ""
但我的代码只是突出显示 ColA 如何将范围添加到代码中。
任何帮助将不胜感激。
Sub formatcell()
Dim Report As Worksheet
Dim lastRow As Integer
Dim i As Integer
Set Report = ActiveSheet
lastRow = Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To lastRow
If Report.Cells(i, 1).Value <> "" Then
Report.Cells(i, 1).Interior.Color = RGB(255, 217, 102)
End If
Next i
End Sub
这样试试:
Dim ws As Worksheet, rng As Range
Set ws = ActiveSheet
On Error Resume Next 'skip error if no values
Set rng = ws.Columns("A").SpecialCells(xlCellTypeConstants)
On Error GoTo 0
If Not rng Is Nothing Then
Application.Intersect(rng.EntireRow, ws.Range("A:M")).Interior.Color = vbYellow
End If
我一直在尝试开发一个突出显示范围(A 到 M)的代码,其中 Col"A" <> ""
但我的代码只是突出显示 ColA 如何将范围添加到代码中。
任何帮助将不胜感激。
Sub formatcell()
Dim Report As Worksheet
Dim lastRow As Integer
Dim i As Integer
Set Report = ActiveSheet
lastRow = Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To lastRow
If Report.Cells(i, 1).Value <> "" Then
Report.Cells(i, 1).Interior.Color = RGB(255, 217, 102)
End If
Next i
End Sub
这样试试:
Dim ws As Worksheet, rng As Range
Set ws = ActiveSheet
On Error Resume Next 'skip error if no values
Set rng = ws.Columns("A").SpecialCells(xlCellTypeConstants)
On Error GoTo 0
If Not rng Is Nothing Then
Application.Intersect(rng.EntireRow, ws.Range("A:M")).Interior.Color = vbYellow
End If