Creating a macro to hide all rows containing currently selected values

MisterBird

New Member
Joined
Aug 9, 2019
Messages
5
I am hoping to create a way to hide rows on multiple sheets based off the text in the currently highlighted cell. So, for instance if I am on Sheet 1 and I am highlighting a cell containing "John Smith", I want to hit a button (from developer inserts) and it will hide all rows (across all 5 sheets) if their column c contains "John Smith".

Is this sort of thing even possible? I am incredibly new to creating macros myself, so I am not sure if this is beyond the limits of excel. Perhaps I would need a add-in to be able to do this?

Thanks!
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Additionally, I want to be able to do this multiple times with different cells, while still maintaining the previously hidden rows.
 
Upvote 0
Yes, "John Smith" would be in the cell all by itself.
Give this macro a try...
Code:
Sub HideRows()
  Dim Text As String, WS As Worksheet
  Text = ActiveCell.Value
  On Error Resume Next
  Application.ScreenUpdating = False
  For Each WS In Worksheets
    With WS.Columns("C")
      .Replace Text, "#N/A", xlWhole, , False, , False, False
      .SpecialCells(xlConstants, xlErrors).EntireRow.Hidden = True
      .Replace "#N/A", Text
    End With
  Next
  Application.ScreenUpdating = True
  On Error GoTo 0
End Sub
 
Upvote 0
Actually, after looking through the macro I realized I had mistakenly told you column "C", when it was actually column "D". After I changed that in the macro it works great! Thank you so much
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

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