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!
 

MisterBird

New Member
Joined
Aug 9, 2019
Messages
5
Additionally, I want to be able to do this multiple times with different cells, while still maintaining the previously hidden rows.
 

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
35,426
Office Version
2010
Platform
Windows
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
 

MisterBird

New Member
Joined
Aug 9, 2019
Messages
5
Rick,

I appreciate your effort, but when I gave it a try it hid every row with text in it.
 

MisterBird

New Member
Joined
Aug 9, 2019
Messages
5
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
 

Forum statistics

Threads
1,078,437
Messages
5,340,275
Members
399,361
Latest member
Linford

Some videos you may like

This Week's Hot Topics

  • Problem with Radio Button's format control
    I am creating an employee evaluation template (a sample is below) Column A is the category Column B, C D, E and F will be ratings (unacceptable...
  • Last Display on userform to a Listbox
    [CODE=vba] lstdisplay.ColumnCount = 15 lstdisplay.RowSource = "A1:O600000" [/CODE] So when i do this it Displays everything on the sheet i am...
  • Rename and move files to a new location
    Dear all, I have an excel file with the following information. The actual file name is at column A but i want to rename it using the following...
  • Help with True/False Formula
    Hello! Am stumped how to fix this formula, in which my result returns 'True', but it should return False. =IF(AG2=True...
  • Clear extra characters from a provided range of cells
    Dear All, I have following code which gives me desired output to remove extra characters from a provided range. But it takes too much time when...
  • Help with Current and highest streaks
    Hi there, I've just joined the forum and this is my first post. I've already spent quite a bit of time searching the net and this forum for a...
Top