Excel VBA - Hide All Rows where value = Active Cell Offset Cell Value?

前端 未结 1 1290
清歌不尽
清歌不尽 2021-01-29 03:32

I have a spreadsheet laid out like so:

A        B            C
12       Row1         Click to Hide
12       Row2         Click to Hide
5        Row3         Clic         


        
相关标签:
1条回答
  • 2021-01-29 03:58

    This will hide the alternative rows, but hide hide the row with ActiveCell:

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        If Target.Count > 1 Then Exit Sub
        If Not Intersect(Target, Range("C:C")) Is Nothing And Target.Value = "Click to Hide" Then
            valu = Cells(Target.Row, 1).Value
            For i = 1 To ActiveSheet.UsedRange.Rows.Count
                If Cells(i, 1).Value = valu Then
                    Cells(i, 1).EntireRow.Hidden = True
                Else
                    Cells(i, 1).EntireRow.Hidden = False
                End If
            Next i
            Target.EntireRow.Hidden = False
        Else
            Rows.Hidden = False
        End If
    End Sub
    
    0 讨论(0)
提交回复
热议问题