ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Hide Rows Based on Cell Result (https://www.excelbanter.com/excel-programming/409356-hide-rows-based-cell-result.html)

bj

Hide Rows Based on Cell Result
 
Hi All

Having difficulty and full disclosure - ** VB Newbie **

I would like to hide rows e.g., 20-25, 51 and 80-90 if the value in cell L15
= "Additional" and expose these same rows if the value in cell L15 = "Final"

Cell L15 is set up using Data | Validation | List | Additional,Final

Any help is appreciated greatly.

Brett

Dave Peterson

Hide Rows Based on Cell Result
 
Rightclick on the worksheet tab that should have this behavior. Select View
code and paste this into the code window that just opened.

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count 1 Then Exit Sub
If Intersect(Target, Me.Range("L15")) Is Nothing Then
Exit Sub
End If

Me.Range("20:25,51:51,80:90").EntireRow.Hidden _
= CBool(LCase(Target.Value) < LCase("final"))

End Sub

It actually shows the rows if that cell is "final". Anything else (blank, too!)
and the rows are hidden.



BJ wrote:

Hi All

Having difficulty and full disclosure - ** VB Newbie **

I would like to hide rows e.g., 20-25, 51 and 80-90 if the value in cell L15
= "Additional" and expose these same rows if the value in cell L15 = "Final"

Cell L15 is set up using Data | Validation | List | Additional,Final

Any help is appreciated greatly.

Brett


--

Dave Peterson

BJ

Hide Rows Based on Cell Result
 
Mr. Peterson you rule! Thanks so much.

"Dave Peterson" wrote:

Rightclick on the worksheet tab that should have this behavior. Select View
code and paste this into the code window that just opened.

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count 1 Then Exit Sub
If Intersect(Target, Me.Range("L15")) Is Nothing Then
Exit Sub
End If

Me.Range("20:25,51:51,80:90").EntireRow.Hidden _
= CBool(LCase(Target.Value) < LCase("final"))

End Sub

It actually shows the rows if that cell is "final". Anything else (blank, too!)
and the rows are hidden.



BJ wrote:

Hi All

Having difficulty and full disclosure - ** VB Newbie **

I would like to hide rows e.g., 20-25, 51 and 80-90 if the value in cell L15
= "Additional" and expose these same rows if the value in cell L15 = "Final"

Cell L15 is set up using Data | Validation | List | Additional,Final

Any help is appreciated greatly.

Brett


--

Dave Peterson



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

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