我正在尝试查找VBA代码,如果“ AB”列中的单元格值为“ Elective”,则该代码将突出显示“ A7:AD100”范围内的适当行。
Sub highlight()
Dim cell As Range
Range(Range("AB7"), Range("AB7").End(xlDown)).Select
For Each cell In Selection
If cell = "Elective" Then Cells.Range($A7, $AD7).Interior.ColorIndex = 10
Next cell
End Sub
由于第1、11、21、23行的Admit Type =“ Elective”,因此仅突出显示。这些行仅在“ A:AD”范围内突出显示(我不希望整个行都突出显示)。
答案 0 :(得分:0)
我找到了适合我的代码
Sub HighlightCells()
Dim rngMyCell As Range
Dim lngLastRow As Long
Application.ScreenUpdating = False
lngLastRow = Cells(Rows.Count, "AB").End(xlUp).Row
For Each rngMyCell In Range("AB7:AB" & lngLastRow)
If StrConv(rngMyCell, vbProperCase) = "Elective" Then
Range("A" & rngMyCell.Row & ":AD" & rngMyCell.Row).Interior.Color = RGB(240, 240, 240)
End If
Next rngMyCell
Application.ScreenUpdating = True
结束子