Toggle Button VBA - hide rows based on cell value

mark9988

Board Regular
Joined
Sep 30, 2005
Messages
90
Hello,

I have two worksheets in my workbook.

Cell A1 in Sheet1 has a validation box that allows values 1,2,3 to be selected

There is a toggle button in Sheet2.
  • If the toggle button is clicked while cell A1 contains value "1", I need rows 10 through 30 hidden in Sheet2
  • If the toggle button is clicked while cell A1 contains value "2", I need rows 15 through 30 hidden in Sheet2
  • If the toggle button is clicked while cell A1 contains value "3", I need rows 20 through 30 hidden in Sheet2

Thank you very much!!
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Why are you using a Toggle button?
Normally a Toggle button is used to do one thing if Toggle button= True and another thing if Toggle button= False

Toggle Buttons are always True or False.

Are you trying to hide or unhide the rows?
 
Upvote 0
Solution
Why are you using a Toggle button?
Normally a Toggle button is used to do one thing if Toggle button= True and another thing if Toggle button= False

Toggle Buttons are always True or False.

Are you trying to hide or unhide the rows?
Yes, I'm trying to hide rows
 
Last edited:
Upvote 0
Yes, I'm trying to hide rows
So you're not wanting to unhide any rows?

Then Try This:
VBA Code:
Private Sub ToggleButton1_Click()
'Modified  6/30/2022  5:38:53 PM  EDT
Select Case Sheets(1).Cells(1, 1).Value

Case 1: Sheets(2).Rows("10:30").Hidden = True
Case 2: Sheets(2).Rows("15:30").Hidden = True
Case 3: Sheets(2).Rows("20:30").Hidden = True

End Select

End Sub
 
Upvote 0
Modify sheet names if needed.
Sometimes when people say Sheet1
It may mean first sheet created
Or first sheet on Task bar

I like it when people say sheet named "Alpha" Or "Bravo" or such.
 
Upvote 0

Forum statistics

Threads
1,215,053
Messages
6,122,882
Members
449,097
Latest member
dbomb1414

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