VBA code to hide rows n-maximum

前端 未结 2 1947
粉色の甜心
粉色の甜心 2021-01-29 15:25

Is there there any code in Excel 2010 VBA that I can use to hide row n (e.g. row 200) to the maximum row?

Btw the name of the sheet in particular is

2条回答
  •  走了就别回头了
    2021-01-29 15:58

    Updated comment: To be clear I interpreted this question as hiding from row 200 to the used row with data (if that last used row exceeded 200)

    Something like this

    code

    Sub HideEm()
        Dim rng1 As Range
        Set rng1 = ActiveSheet.Cells.Find("*", [a1], xlValues, , , xlPrevious)
        If Not rng1 Is Nothing Then
            If rng1.Row > 200 Then Rows("200:" & rng1.Row).Hidden = True
        End If
    End Sub
    

    to work on a specific sheet

    Sub HideEm()
    Dim ws As Worksheet
    Dim rng1 As Range
    Set ws = Sheets("main")
    Set rng1 = ws.Cells.Find("*", ws.[a1], xlValues, , , xlPrevious)
    If Not rng1 Is Nothing Then
        If rng1.Row > 200 Then ws.Rows("200:" & rng1.Row).Hidden = True
    End If
    End Sub
    

提交回复
热议问题