[英]Conditional formatting to highlight specific cells but not empty and text cells VBA
I have a macro which highlights cells outside a range.我有一个宏可以突出显示范围之外的单元格。 The only problem with it, is that it also highlights all empty cells and cells with text.
它唯一的问题是它还会突出显示所有空单元格和带有文本的单元格。 Is there a way for it to ignore these?
有没有办法让它忽略这些?
Here is my code这是我的代码
Sub Highlight()
'
' Highlight good values
Application.ScreenUpdating = False
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Activate
With ActiveSheet.Rows("18:79")
.FormatConditions.Add Type:=xlCellValue, Operator:=xlNotBetween, _
Formula1:="=$C18", Formula2:="=$D18"
.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With .FormatConditions(1).Font
.Color = -16752384
.TintAndShade = 0
End With
With .FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 13561798
.TintAndShade = 0
End With
.FormatConditions(1).StopIfTrue = False
End With
Next ws
Application.ScreenUpdating = True
End Sub
You currently only have a row limitation to the range you are applying the conditional formatting to.您目前对应用条件格式的范围只有行限制。 If you want to limit the impacted range you just need to change your
With
to have both a Row and a Column limitation.如果您想限制受影响的范围,您只需将
With
更改为同时具有Row和Column限制。
Update This:更新这个:
With ActiveSheet.Rows("18:79")
To This:对此:
With ActiveSheet.Range("A18:O79")
If each sheet has the SAME row range (18:79) but the columns have a VARYING range you just need to create a last column variable to create your dynamic range如果每个工作表具有相同的行范围 (18:79) 但列具有不同的范围,则您只需要创建最后一列变量即可创建动态范围
Sub Highlight()
Dim ws As Worksheet, LC As Long
For Each ws In ActiveWorkbook.Worksheets
LC = ws.Cells(18, ws.Columns.Count).End(xlToLeft).Column
With ws.Range(ws.Cells(18, 1), ws.Cells(79, LC))
'Formatting goes here
End With
Next ws
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.