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!
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
I think we need more specific details.
Like sheet name

And you said:
"Button to hide/unhide rows containing specific text in column G"
Nothing specific here
 
Upvote 0
Based on the info given, maybe this will work.
But having no idea about anything else with the sheet, maybe not.
VBA Code:
Sub Button9_Click()
    If Not ActiveSheet.AutoFilterMode Then
        Range("G:G").AutoFilter Field:=1, Criteria1:="<>" & "specific text"
    Else
        Range("G:G").AutoFilter
    End If
End Sub
 
Upvote 0
I think we need more specific details.
Like sheet name

And you said:
"Button to hide/unhide rows containing specific text in column G"
Nothing specific here
Sheet name is UK 23-24 US 2023
Text that needs to be recognised is “Sent to HMRC/IRS”
I have multiple phrases written in Column G (as in each row in column G contains one of 8 different phrases) and need to able to hide and unhide rows containing the specific text written above

Please let me know if you need more information about this

Thanks
 
Upvote 0
Th
Based on the info given, maybe this will work.
But having no idea about anything else with the sheet, maybe not.
VBA Code:
Sub Button9_Click()
    If Not ActiveSheet.AutoFilterMode Then
        Range("G:G").AutoFilter Field:=1, Criteria1:="<>" & "specific text"
    Else
        Range("G:G").AutoFilter
    End If
End Sub
Thank you but this didn’t work, sorry
When clicking the button it specifically highlights “Criterial:=“ and says names argument not found
 
Upvote 0
When clicking the button it specifically highlights “Criterial:=“ and says names argument not found
Because that is not what I posted
It's Criteria1 --- that's the number 1 at the end
 
Upvote 0
Because that is not what I posted
It's Criteria1 --- that's the number 1 at the end
Oh sorry about that, I’ve changed it to a 1 and it’s worked, so thank you.

As it now works, I’ve noticed that I need it to be more specific.

The specific rows that need to be hidden/unhidden, (on top of having specific text in column G) also need to have no text at all in column L and must have text (a calendar date) in column N.

To summarise, specific text in column G, no text in column L and text (not specific) in column N for that particular row to hide/unhide

Sorry about the extra requests

Thanks
 
Upvote 0
OK, I think that eliminates simple filtering due to the possible combinations and changes that could occur to visible rows.

You've indicated each row in column G contains one of 8 different phrases.
Also asked that code be for Button9.
Is it reasonable to think you have individual buttons intended for hiding each phrase as required,
and another one to unhide everything?
 
Upvote 0
OK, I think that eliminates simple filtering due to the possible combinations and changes that could occur to visible rows.

You've indicated each row in column G contains one of 8 different phrases.
Also asked that code be for Button9.
Is it reasonable to think you have individual buttons intended for hiding each phrase as required,
and another one to unhide everything?
Sorry I’m not going to act like I fully understand (as I’m the dumb one here)

I only need that specific button for that phrase, the other 7 phrases don’t need a button at all
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,223,884
Messages
6,175,177
Members
452,615
Latest member
bogeys2birdies

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