ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   IF Cell contents = "a" then hide row (https://www.excelbanter.com/excel-programming/406188-if-cell-contents-%3D-then-hide-row.html)

Darin Kramer

IF Cell contents = "a" then hide row
 


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 ***

JLGWhiz

IF Cell contents = "a" then hide row
 
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



"Darin Kramer" wrote:



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 ***


RyanH

IF Cell contents = "a" then hide row
 
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

"Darin Kramer" wrote:



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 ***


Darin Kramer

IF Cell contents = "a" then hide row
 


Thanks Guys - works perfectly!

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


All times are GMT +1. The time now is 06:34 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com