简体   繁体   中英

Hide group of rows in excel

I want to hide certain group of rows where 1st row after blank row is "xyz" untill next blank row occours. eg

**heloo**
a
b

**xyz**
as
df

**hello**
g
j

**xyz**
ghj
gh
jk
jk

I want output to be as

**heloo**
a
b

**hello**
g

Looks like you have edited your question a bit, so the inputs are slighty different. However, this is the idea of what you need. Basically, define a range. Iterate through it until you find xyz. Set a flag to start hiding every row in the iteration until you find a blank row.

Sub HideRows()
    Set r = Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row)
    hiderow = False
    For Each c In r.Cells
        If Left(c.Value, 3) = "xyz" Then
            hiderow = True
        ElseIf Len(c.Value) = 0 Then
            hiderow = False
        End If
        If hiderow Then
            c.Select
            Selection.EntireRow.Hidden = True
        End If
    Next c
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM