VBA:Toggle hiding rows based on cell value

kemidan51

New Member
Joined
Jul 12, 2011
Messages
10
Ok I have a spreadsheet that I am developing for use at work for Capability,

I have a cell G8 that using a drop down list for 3 variables "Regular" "Max limit" "Min Limit"

In a series of calculation rows (because theres 30 sets or the same calculation in each row) I have a row for Maximum spec limit Row 22 Nominal Spec limit Row 23 and Minimum Spec limit Row 24.

What i want the macro to do is to always and actively run with out having to click a button. So when the user picks "Min Limit" from G8 it will hide row 22 and in the same moment if I pick "Max limit" from G8 it will unhide 22 and hide row 24, ALSO if they pick "Regular" again from G8 it will unhide which ever rows were previously hidden and so that all 3 rows are showing.

The purpose for me to hide these is for visual purposes to hide the actual line of data on the graph because its not valid

Here's what we tried. We triad Radio buttons and it works HOWEVER the cells in the rows that would remain unhidden have IF statements to change math formulas AS WELL if cell G8 = to specific value inside the dropdown list. Radio buttons do not allow the cell values to change

Can anyone help me out?
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Try this: right click the sheet tab, select View Code and paste in

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address(False, False) = "G8" Then
    Select Case LCase(Target.Value)
        Case "max limit": Rows(24).Hidden = True: Rows(22).Hidden = False
        Case "min limit": Rows(24).Hidden = False: Rows(22).Hidden = True
        Case Else: Rows("22:24").Hidden = False
    End Select
End If
End Sub
 
Upvote 0
I cant seam to copy and paste your code with and running it with out it asking me to save it under a name and creating a new sub line thats blank. its like its not recognizing it as a named macro. what could i be doing wrong?
 
Upvote 0
It is event code that goes in the sheet's code module. Right click the sheet tab, select View Code and paste in the code.

Press ALT + Q to close the code window then try changing the value of G8.
 
Upvote 0
Ok I saw the words "Select Case Lcase" is that looking for "lowercase" letters? if so Ill have to apologize but The first letters are capitalized does that make a difference?

Also how would it change the syntax if i were to tell you the values would change to "Regular (±)" "One Sided (+)" and "One Sided (-)" per my bosses request
 
Upvote 0
OK VoG just to try it out i added to the datavalidation list for G8 the words max limit and min limit and the code works!!! soo what do i need to do to get ti to read for "One Sided (-)" and "One Sided (+)"? ver batim
 
Upvote 0
Maybe like this

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address(False, False) = "G8" Then
    Select Case LCase(Target.Value)
        Case "one sided (+)": Rows(24).Hidden = True: Rows(22).Hidden = False
        Case "one sided (-)": Rows(24).Hidden = False: Rows(22).Hidden = True
        Case Else: Rows("22:24").Hidden = False
    End Select
End If
End Sub

The LCase() makes the test case-insensitive. It doesn't matter what the actual case is in your drop down.
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,713
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top