VBA hidden row.

jamiguel77

Active Member
Joined
Feb 14, 2006
Messages
378
Office Version
  1. 2016
  2. 2010
  3. 2007
Platform
  1. Windows
  2. Web
hi all how to hide a row if in column F exist a cell that contains these word: "Mike"

if F5 = "Mike" and F18 = "Mike"

i want hide row 5 and 18, how to?

thanks
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Code:
Sub HideMike()
    Dim i As Long, lr As Long
    lr = Range("F" & Rows.Count).End(xlUp).Row
    For i = 1 To lr
        If Range("F" & i) = "Mike" Then
            Range("F" & i).EntireRow.Hidden = True
        End If
    Next i
End Sub
 
Upvote 0
Code:
Sub HideRows()
    Dim WS As Worksheet
    Dim RowsToHide As Range

    Set WS = ActiveSheet
    With WS
        If .AutoFilterMode Then .AutoFilterMode = False
        .Columns.AutoFilter Field:=.Columns("F").Column, Criteria1:="Mike"
        With .UsedRange
            Set RowsToHide = Application.Intersect(.SpecialCells(xlCellTypeVisible).EntireRow, .Resize(.Rows.Count - 1).Offset(1).EntireRow)
        End With
        If .AutoFilterMode Then .AutoFilterMode = False
        If Not RowsToHide Is Nothing Then
            RowsToHide.EntireRow.Hidden = True
        End If
    End With
End Sub
 
Upvote 0
Simpler just to filter for "not equal to Mike"?
Code:
Sub HideMike()
  Columns("F").AutoFilter Field:=1, Criteria1:="<>Mike"
End Sub

@jamiguel77
Note that the AutoFilter suggestions do require that that row 1 of your sheet is a heading row with actual data below that (or at least that Mike cannot appear in cell F1). If you don't have a header row and you still want further suggestions, then post back with details.
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,279
Members
449,075
Latest member
staticfluids

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