基于 IFERROR VLOOKUP 结果的条件格式行
Conditional Format Row based on IFERROR VLOOKUP result
我正在尝试对 A 列中未通过我的 IFERROR VLOOKUP 公式的每一行进行条件格式化。我已经到达可以突出显示 IFERROR 单元格的位置,但现在不是整个单元格。请帮忙。这是我目前所拥有的:
Range("A2:AH2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="=""Not VA Student"""
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
我不清楚你的 IFERROR VLOOKUP 是什么意思,因为我在你的代码中看不到这个。
我认为您只想突出显示在规定范围内找到 "Not VA Student" 的行。您当前的代码对单个单元格执行此操作。
我认为范围 selected 可能过大,因为您 select 到指定列限制内的 sheet 底部。
尝试以下操作。我对现有代码进行了小幅修改,归功于 user3598756
Private Sub HighlightRows()
Dim wb As Workbook
Dim ws As Worksheet
Dim FoundCell As Range
Dim rng As Range
Dim FirstFound As String
Set wb = ThisWorkbook
Set ws = wb.Worksheets("Sheet1") ' change as appropriate
Const fnd As String = "Not VA Student"
With ws.Range("A2:AH" & ws.Range("AH2").End(xlDown).Row) '<--| reference the range to search into ''@qharr: this seems excessive to me
Set FoundCell = .Find(what:=fnd, after:=.Cells(.Cells.Count)) '<--| find the first cell
If Not FoundCell Is Nothing Then 'Test to see if anything was found
FirstFound = FoundCell.Address ' <--| store the first found cell address
Set rng = FoundCell '<--| initialize the range collecting found cells. this to prevent first 'Union()' statement from failing due to 'rng' being 'Nothing'
Do
Set rng = Union(rng, FoundCell) 'Add found cell to rng range variable
'Find next cell with fnd value
Set FoundCell = .FindNext(after:=FoundCell)
Loop While FoundCell.Address <> FirstFound 'Loop until cycled through all finds
End If
End With
If Not rng Is Nothing Then rng.EntireRow.Interior.Color = 65535
End Sub
我正在尝试对 A 列中未通过我的 IFERROR VLOOKUP 公式的每一行进行条件格式化。我已经到达可以突出显示 IFERROR 单元格的位置,但现在不是整个单元格。请帮忙。这是我目前所拥有的:
Range("A2:AH2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="=""Not VA Student"""
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
我不清楚你的 IFERROR VLOOKUP 是什么意思,因为我在你的代码中看不到这个。
我认为您只想突出显示在规定范围内找到 "Not VA Student" 的行。您当前的代码对单个单元格执行此操作。
我认为范围 selected 可能过大,因为您 select 到指定列限制内的 sheet 底部。
尝试以下操作。我对现有代码进行了小幅修改,归功于 user3598756
Private Sub HighlightRows()
Dim wb As Workbook
Dim ws As Worksheet
Dim FoundCell As Range
Dim rng As Range
Dim FirstFound As String
Set wb = ThisWorkbook
Set ws = wb.Worksheets("Sheet1") ' change as appropriate
Const fnd As String = "Not VA Student"
With ws.Range("A2:AH" & ws.Range("AH2").End(xlDown).Row) '<--| reference the range to search into ''@qharr: this seems excessive to me
Set FoundCell = .Find(what:=fnd, after:=.Cells(.Cells.Count)) '<--| find the first cell
If Not FoundCell Is Nothing Then 'Test to see if anything was found
FirstFound = FoundCell.Address ' <--| store the first found cell address
Set rng = FoundCell '<--| initialize the range collecting found cells. this to prevent first 'Union()' statement from failing due to 'rng' being 'Nothing'
Do
Set rng = Union(rng, FoundCell) 'Add found cell to rng range variable
'Find next cell with fnd value
Set FoundCell = .FindNext(after:=FoundCell)
Loop While FoundCell.Address <> FirstFound 'Loop until cycled through all finds
End If
End With
If Not rng Is Nothing Then rng.EntireRow.Interior.Color = 65535
End Sub