ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   hide row based on cell value (https://www.excelbanter.com/excel-worksheet-functions/256350-hide-row-based-cell-value.html)

jat

hide row based on cell value
 
i have a worksheet that i want to hide rows based on cell value.

if cell B3 is blank, then i need rows 4,5 and 6 to be hidden, B3 contains
data than row 4 is visible.

if cell H3 is blank, then rows 5 and 6 need to be hidden. if b3 and h3 have
data, then rows 4 and 5 are visible.

if cell n3 is blank then row 6 is hidden.

i have the following so far:

Private Sub Worksheet_change(ByVal Target As Range)
Application.EnableEvents = False
If Target.Address(0, 0) = "P28" Then
Select Case LCase(Target.Value)
Case "target": MainMenu 'this brings up a user input box and works
End Select
End If

If Target.Address(0, 0) = "B3" Then
If Range("B3") < "" Then Call hideum
End If
Application.EnableEvents = True

End Sub
<
--
Sub hideum()
Dim i As Long
n = Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To n
If Cells(i, 1).Value = "XXX" Then
Rows(i).Hidden = True
End If
Next
End Sub

i can run the hideum macro manually but it does not fire on it's own. any
suggestions?

Dave Peterson

hide row based on cell value
 
It works ok for me.

Are you sure that it's failing--maybe you don't have any XXX in column A
(upper/lower case matters in your code).



jat wrote:

i have a worksheet that i want to hide rows based on cell value.

if cell B3 is blank, then i need rows 4,5 and 6 to be hidden, B3 contains
data than row 4 is visible.

if cell H3 is blank, then rows 5 and 6 need to be hidden. if b3 and h3 have
data, then rows 4 and 5 are visible.

if cell n3 is blank then row 6 is hidden.

i have the following so far:

Private Sub Worksheet_change(ByVal Target As Range)
Application.EnableEvents = False
If Target.Address(0, 0) = "P28" Then
Select Case LCase(Target.Value)
Case "target": MainMenu 'this brings up a user input box and works
End Select
End If

If Target.Address(0, 0) = "B3" Then
If Range("B3") < "" Then Call hideum
End If
Application.EnableEvents = True

End Sub
<
--
Sub hideum()
Dim i As Long
n = Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To n
If Cells(i, 1).Value = "XXX" Then
Rows(i).Hidden = True
End If
Next
End Sub

i can run the hideum macro manually but it does not fire on it's own. any
suggestions?


--

Dave Peterson

jat

hide row based on cell value
 
probably would have helped if i had the code in the worksheet and not the
module.

thankx,

jat


"Dave Peterson" wrote:

It works ok for me.

Are you sure that it's failing--maybe you don't have any XXX in column A
(upper/lower case matters in your code).



jat wrote:

i have a worksheet that i want to hide rows based on cell value.

if cell B3 is blank, then i need rows 4,5 and 6 to be hidden, B3 contains
data than row 4 is visible.

if cell H3 is blank, then rows 5 and 6 need to be hidden. if b3 and h3 have
data, then rows 4 and 5 are visible.

if cell n3 is blank then row 6 is hidden.

i have the following so far:

Private Sub Worksheet_change(ByVal Target As Range)
Application.EnableEvents = False
If Target.Address(0, 0) = "P28" Then
Select Case LCase(Target.Value)
Case "target": MainMenu 'this brings up a user input box and works
End Select
End If

If Target.Address(0, 0) = "B3" Then
If Range("B3") < "" Then Call hideum
End If
Application.EnableEvents = True

End Sub
<
--
Sub hideum()
Dim i As Long
n = Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To n
If Cells(i, 1).Value = "XXX" Then
Rows(i).Hidden = True
End If
Next
End Sub

i can run the hideum macro manually but it does not fire on it's own. any
suggestions?


--

Dave Peterson
.



All times are GMT +1. The time now is 12:11 AM.

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