Toggle Button to Hide/Unhide column based on specific text in rows

onthegreen03

Board Regular
Joined
Jun 30, 2016
Messages
148
Office Version
  1. 365
Platform
  1. Windows
Hi All -

I want to add a Toggle Button, that when clicked will search all rows in column C of my spreadsheet and hide the rows which contain the word Vacant. Obviously, when the button is clicked again it will unhide all rows that contain the word Vacant. Can anyone send me the VBA code that will get this done? I've looked around on line and even tried a few times and can't seem to figure it out. Thanks in advance!
 
OK I have figured out how to do this:
Using A Toggle Button:
Try this:
VBA Code:
Private Sub ToggleButton1_Click()
'Modified  6/30/2022  1:39:11 PM  EDT
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "C").End(xlUp).Row
   
    If ToggleButton1.Value = True Then
        ToggleButton1.Caption = "Hidden"
            For i = 1 To Lastrow
                If Cells(i, 3).Value = "Vacant" Then Rows(i).Hidden = True
            Next
    End If


    If ToggleButton1.Value = False Then
        ToggleButton1.Caption = "Not Hidden"
        For i = 1 To Lastrow
            If Cells(i, 3).Value = "Vacant" Then Rows(i).Hidden = False
        Next
    End If
Application.ScreenUpdating = True
End Sub
this would but i can't get it to work. I've been at this for hours but none of it makes sense. I have a header in row 1, and instead of assigning static columns ot be hidden with toggle (because it is so many columns and i seem to run into issues beyond certain number of columns in range but also if range changes then i have to redo all of it) i would like for it to search the top row (row 1) for the word "performance", then all columns in that range (say column range BB:TX would toggle. Can you please advise what i would modify here? thank you
 
Upvote 0

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
this would but i can't get it to work. I've been at this for hours but none of it makes sense. I have a header in row 1, and instead of assigning static columns ot be hidden with toggle (because it is so many columns and i seem to run into issues beyond certain number of columns in range but also if range changes then i have to redo all of it) i would like for it to search the top row (row 1) for the word "performance", then all columns in that range (say column range BB:TX would toggle. Can you please advise what i would modify here? thank you
I suggest you start a new posting and explain in detail what you're attempting to achieve.
 
Upvote 0

Forum statistics

Threads
1,214,848
Messages
6,121,914
Members
449,054
Latest member
luca142

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