2016-10-13 6 views
0

ich den folgenden Code bin mit Zeilen verstecken basierend auf Zellwert:anzeigen Reihe basierend auf Zellwert - Excel VBA

Sub HideN() 

Dim RowCnt As Long, uRng As Range 

BeginRow = 8 
EndRow = 232 
ChkCol = 6 

    For RowCnt = BeginRow To EndRow 
     If Cells(RowCnt, ChkCol).Value = 0 Then 
     If uRng Is Nothing Then 
      Set uRng = Cells(RowCnt, ChkCol) 
     Else 
      Set uRng = Union(uRng, Cells(RowCnt, ChkCol)) 
     End If 

     End If 
    Next RowCnt 

If Not uRng Is Nothing Then uRng.EntireRow.Hidden = True 

End Sub 

Was ich ändern zu tun haben, wenn ich möchte auch die Zeilen sichtbar machen, wo die Zellwert ist 1?

Vielen Dank im Voraus!

MD

Antwort

0

Sie könnten nur eine zusätzliche If Anweisung hinzufügen, nein ?:

Sub HideN() 

Dim RowCnt As Long, uRng As Range 

BeginRow = 8 
EndRow = 232 
chkcol = 6 

For RowCnt = BeginRow To EndRow 
    If Cells(RowCnt, chkcol).Value = 0 Then 
     If uRng Is Nothing Then 
      Set uRng = Cells(RowCnt, chkcol) 
     Else 
      Set uRng = Union(uRng, Cells(RowCnt, chkcol)) 
     End If 
    End If 
    If Cells(RowCnt, chkcol).Value = 1 Then ' This is the new line to add 
     Rows(RowCnt).EntireRow.Hidden = False 
    End If 
Next RowCnt 

If Not uRng Is Nothing Then uRng.EntireRow.Hidden = True 

End Sub 
3

Dies wird alles ausblenden, die 0 sind und alle anderen sichtbar machen.

Sub HideN() 

Dim RowCnt As Long 
Dim BeginRow&, EndRow&, ChkCol& 

BeginRow = 8 
EndRow = 232 
ChkCol = 6 

    For RowCnt = BeginRow To EndRow 
     Rows(RowCnt).Hidden = Cells(RowCnt, ChkCol).Value = 0 
    Next RowCnt 



End Sub 

Natürlich können Sie das gleiche mit einem Filter tun.

+1

Ein hervorragendes Beispiel für einen Booleschen Wert auf das Ergebnis eines Booleschen Ausdruck Einstellung - 1 – YowE3K

Verwandte Themen