ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Macro to show only rows with X (https://www.excelbanter.com/excel-discussion-misc-queries/261477-macro-show-only-rows-x.html)

Jeremy

Macro to show only rows with X
 
How would I write a script or macro to display rows that have and x in "A"
and hide all other rows?


Thank you

Jacob Skaria

Macro to show only rows with X
 
With data starting in ColA; try

Cells.AutoFilter Field:=1, Criteria1:="=x"

--
Jacob (MVP - Excel)


"Jeremy" wrote:

How would I write a script or macro to display rows that have and x in "A"
and hide all other rows?


Thank you


Mike

Macro to show only rows with X
 
Option Explicit
Sub Remove_Unwanted_Rows()
Dim rng As Range
Dim cell, RowArray As Range
Set rng = ActiveSheet.Range(Cells(1, "A"), Cells(Rows.Count, "A").End(xlUp))
For Each cell In rng
Select Case cell
Case Is < "x"
If RowArray Is Nothing Then
Set RowArray = cell.EntireRow
Else
Set RowArray = Union(RowArray, cell.EntireRow)
End If
End Select
Next cell
On Error Resume Next
RowArray.EntireRow.Hidden = True
Err.Clear
End Sub

"Jeremy" wrote:

How would I write a script or macro to display rows that have and x in "A"
and hide all other rows?


Thank you



All times are GMT +1. The time now is 01:26 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com