IF Cell contents = "a" then hide row

D

Darin Kramer

Hi guys,

I have in column K three possible types of data, a,b or c (only one per
cell)

If the value = a or b I want the row to be visible (ie hide all rows
that contain c)

I then need anotehr set of VB to to repeat the excercise for the other
option - ie first unide all, then if value = b or c row is visible (ie
hide all rows that contain a)

If I can just be helped with the first scenario, Im sure I could
replicate it for the second....

Thanks!!!!!

Regards

D



*** Sent via Developersdex http://www.developersdex.com ***
 
J

JLGWhiz

This would leave all rows with "b" or "c" values
within myRange visible.

Sub hiderow()
Dim r As Range
Set myRange = ActiveSheet.Range("K2:K100")
For Each r In myRange
If r.Value <> "a" Then
r.EntireRow.Hidden = True
End If
Next
End Sub
 
R

RyanH

hide rows a & b
Sub Hideab()

Dim LastRow As Long

'last row in Col.K
LastRow = Cells(Rows.Count, "K").End(xlUp).Row

'unhides all rows
Cells.EntireRow.Hidden = False

'hides all rows with a or b in Col.K
For i = 1 To LastRow
If Cells(i, 11) = "a" Or Cells(i, 11) = "b" Then
Rows(i).EntireRow.Hidden = True
End If
Next i

End Sub

Sub Hidebc()

Dim LastRow As Long

'last row in Col.K
LastRow = Cells(Rows.Count, "K").End(xlUp).Row

'unhides all rows
Cells.EntireRow.Hidden = False

'hides all rows with b or c in Col. K
For i = 1 To LastRow
If Cells(i, 11) = "b" Or Cells(i, 11) = "c" Then
Rows(i).EntireRow.Hidden = True
End If
Next i

End Sub
 
R

RyanH

Be sure to give credit where credit is due. If the responses help you,
please click yes the post was helpful.

Thanks,
we all appreciate it
 
G

Gord Dibben

"All" meaning those who use the CDO Interface to post.


Gord Dibben MS Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top