2017-11-22 1 views
0

Ich versuche, jede Zeile konditionell formatieren, die meine IFERROR SVERWEIS Formel in Spalte A fehlschlägt. Ich habe zu wo bekomme ich die IFERROR Zelle zu markieren, aber nicht die gesamte jetzt. Bitte helfen Sie. Das ist, was ich habe, so weit:Bedingte Format Zeile basierend auf IFERROR SVERWEIS Ergebnis

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 
+0

Wollen Sie wirklich für alle Zeilen von Zeile 2 bis Ende des Blattes gelten? Das scheint übertrieben? Und markieren Sie nur Zeile, in der Not VA Student gefunden wird? – QHarr

+0

Ja, ich versuche nur Zeilen zu markieren, in denen Not VA Student gefunden wurde. –

+0

versuchen Sie Code wie pro Antwort ich gepostet. Chage Blatt Name wie geeignet. Platz im Standardmodul. – QHarr

Antwort

0

Es ist mir unklar, was Sie von Ihrem IFERROR VLOOKUP gemeint, wie ich dies nicht in Ihrem Code sehen.

Ich denke, dass Sie nur Zeilen markieren möchten, in denen "Not VA Student" in dem festgelegten Bereich gefunden wird. Ihr aktueller Code tut dies für einzelne Zellen.

Ich denke, dass der ausgewählte Bereich wahrscheinlich übermäßig ist, indem Sie innerhalb der angegebenen Spaltengrenzen bis zum unteren Rand des Blattes wählen.

Versuchen Sie Folgendes. Ich habe geringfügige Änderungen am bestehenden Code gemacht, Kredite an 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 
+0

Das hat perfekt funktioniert. Vielen Dank! –

Verwandte Themen