Here is the link of my previous question related to hiding columns based on selecting a cell from an input box:
How to Correct a macro that hides columns in worksheets based on selecting a cell from an input box
The question answered perfectly by (tailer), who provide the correct macro.
Today I modify the code to hide the rows (see related paragraph below).
The macro code to hides rows in worksheets based on selecting a cell from an input box:
Sub HideRowsAllVisibleUnprotSheets()
Dim ws As Worksheet
Dim InputRng As Range
Dim c As Range, vMch
Dim xTitleId As String
xTitleId = "Choose the cell you want to hide rows in all visible unprotected sheets in this workbook, based on the value of that cell."
On Error Resume Next
Set InputRng = Application.InputBox("Select one cell :", xTitleId, Selection.Address, Type:=8)
On Error GoTo 0
If InputRng Is Nothing Then Exit Sub ' cancel InputBox
If InputRng.Cells.CountLarge > 1 Then ' select multiple cells
MsgBox "Please selecte ONE cell."
Exit Sub
End If
If Len(InputRng.Value) = 0 Then ' blank cell
MsgBox "Because the selected cell is empty, the macro was not executed."
Exit Sub
End If
For Each ws In ActiveWorkbook.Worksheets
'If the sheet is hidden or protected go to next sheet
If ws.Visible And (Not ws.ProtectContents) Then
For Each c In ws.UsedRange.rows ' loop through rows
vMch = Application.Match(InputRng.Value, c, 0) ' search target value
If Not IsError(vMch) Then ' found
c.EntireRow.Hidden = True
End If
Next c
End If
Next ws
End Sub