Hide/Unhide Ranges

Snoopie

New Member
Joined
Mar 20, 2019
Messages
5
Hello All,

Seeking some assistance, thanks in advance to anyone that can assist !

I placed 5x Radio Buttons to use for filtering the ranges of data i have.
Range1 = 14-33
Range2 = 37-56
Range3 = 60-79
Range4 = 83-102
I also have a header range of 1-13 which must always be visible.

When i select the radio button i must click it again to disable the selection before i can choose another, i was of the understanding that the radio button reset the existing selection when you select another?

Here's my code:
Sub OptionButton15_Click()
Range("34:1000").EntireRow.Hidden = Not Range("34:1000").EntireRow.Hidden
End Sub
Sub OptionButton16_Click()
Range("14:36,57:1000").EntireRow.Hidden = Not Range("14:36,57:1000").EntireRow.Hidden
End Sub
Sub OptionButton17_Click()
Range("14:59,80:1000").EntireRow.Hidden = Not Range("14:59,80:1000").EntireRow.Hidden
End Sub
Sub OptionButton18_Click()
Range("14:82,103:1000").EntireRow.Hidden = Not Range("14:82,103:1000").EntireRow.Hidden
End Sub
Sub OptionButton19_Click()
Range("1000:1001").EntireRow.Hidden = Not Range("1000:1001").EntireRow.Hidden
End Sub
 

Some videos you may like

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

jmacleary

Well-known Member
Joined
Oct 5, 2015
Messages
1,026
Office Version
  1. 365
  2. 2007
Platform
  1. Windows
Hi there. You say
i was of the understanding that the radio button reset the existing selection when you select another
I'm not sure exactly what you mean here, but clicking a button will always just execute the code associated with it. As you have overlapping ranges and are using a toggle effect you will get some strange results. Why not replace the code in each with something like this (OptionButton15 shown):
Code:
Sub OptionButton15_Click()
Range("14:1001").EntireRow.Hidden = True
Range("14:36,57:1000").EntireRow.Hidden = False
End Sub
I assume you just want to see the ranges you have selected, but if instead you want to only see the other rows, just replace the true and false with false and true.
 

Snoopie

New Member
Joined
Mar 20, 2019
Messages
5
This was my final code which works great.
Now i just need to have it scroll to the top each time a selection is made.
Thanks for your help @jmacleary.

Code:
Sub OptionButton15_Click()
Worksheets("mysheet").Range("1:1000").EntireRow.Hidden = False
End Sub
Sub OptionButton16_Click()
Worksheets("mysheet").Range("34:1000").EntireRow.Hidden = True
Worksheets("mysheet").Range("1:13,14:33").EntireRow.Hidden = False
End Sub
Sub OptionButton17_Click()
Worksheets("mysheet").Range("14:36,57:1000").EntireRow.Hidden = True
Worksheets("mysheet").Range("1:13,37:56").EntireRow.Hidden = False
End Sub
Sub OptionButton18_Click()
Worksheets("mysheet").Range("14:59,80:1000").EntireRow.Hidden = True
Worksheets("mysheet").Range("1:13,60:79").EntireRow.Hidden = False
End Sub
Sub OptionButton19_Click()
Worksheets("mysheet").Range("14:82,103:1000").EntireRow.Hidden = True
Worksheets("mysheet").Range("1:13,83:102").EntireRow.Hidden = False
End Sub
 

Snoopie

New Member
Joined
Mar 20, 2019
Messages
5
Which I now managed to solve with:

Code:
Sub OptionButton15_Click()
Worksheets("Mako").Range("1:1000").EntireRow.Hidden = False
ActiveWindow.ScrollColumn = 1
ActiveWindow.ScrollRow = 1
End Sub
Sub OptionButton16_Click()
Worksheets("Mako").Range("34:1000").EntireRow.Hidden = True
Worksheets("Mako").Range("1:13,14:33").EntireRow.Hidden = False
ActiveWindow.ScrollColumn = 1
ActiveWindow.ScrollRow = 1
End Sub
Sub OptionButton17_Click()
Worksheets("Mako").Range("14:36,57:1000").EntireRow.Hidden = True
Worksheets("Mako").Range("1:13,37:56").EntireRow.Hidden = False
ActiveWindow.ScrollColumn = 1
ActiveWindow.ScrollRow = 1
End Sub
Sub OptionButton18_Click()
Worksheets("Mako").Range("14:59,80:1000").EntireRow.Hidden = True
Worksheets("Mako").Range("1:13,60:79").EntireRow.Hidden = False
ActiveWindow.ScrollColumn = 1
ActiveWindow.ScrollRow = 1
End Sub
Sub OptionButton19_Click()
Worksheets("Mako").Range("14:82,103:1000").EntireRow.Hidden = True
Worksheets("Mako").Range("1:13,83:102").EntireRow.Hidden = False
ActiveWindow.ScrollColumn = 1
ActiveWindow.ScrollRow = 1
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,109,360
Messages
5,528,235
Members
409,809
Latest member
VICKRAM

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
  • VBA COUNTIF SOLUTION
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
  • INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top