2016-10-13 3 views
0

私は、セルの値に基づいて行を非表示にするには、次のコードを使用しています:私も行を再表示したい場合、私は変更する必要はない表示する行 - エクセル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 

何セルの値は1ですか?

ありがとうございます!

MD

答えて

0

あなただけの追加Ifステートメントを追加することができ、ノー?:

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

これが0であることすべてを隠し、他のすべてを再表示します。

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 

もちろん、フィルタでも同じことができます。

+1

ブール式の結果にブール値を設定する優れた例 - 1 – YowE3K