Button to hide/unhide rows with specific text

Rick127

New Member
Joined
Sep 20, 2024
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Hi
I have inserted a button using the developer tab.

I want to click the button to hide/unhide rows containing specific text in column G

Can anyone help with the Macro for this?

It starts with Sub Button9_Click( )

Thanks!
 
Use this for the code of your Button9 to hide rows
VBA Code:
Sub Button9_Click()
   
    Dim lastRow As Long, cel As Range
   
    With Sheets("UK 23-24 US 2023")
        lastRow = .Range("G" & .Rows.Count).End(xlUp).Row
        For Each cel In .Range("G2:G" & lastRow)
            If cel = "Sent to HMRC/IRS" Then
                If IsEmpty(cel.Offset(, 5)) Then
                    If IsDate(cel.Offset(, 7)) Then
                        cel.EntireRow.Hidden = True
                    End If
                End If
            End If
        Next cel
    End With
       
End Sub
and add another button (for me it was Button10) to unhide all rows
VBA Code:
Sub Button10_Click()
Sheets("UK 23-24 US 2023").Rows.Hidden = False
End Sub

Hope that helps
It works, thank you!
 
Upvote 0

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
You're welcome, thanks for letting me know.
Would be appreciated if you would also mark the post that was the solution
Thanks
 
Upvote 0

Forum statistics

Threads
1,222,564
Messages
6,166,818
Members
452,074
Latest member
Alexinho

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