Consulting

Results 1 to 2 of 2

Thread: Hide Rows in VBA

  1. #1

    Exclamation Hide Rows in VBA

    I want to hide rows on the top of the page as total rows of data increases. I want to unhide constant rows so it is easy for printing. However, my code does not work. Anyone can help me with that? Really thanks.

    My way is first, to detect the last row with data in the Excel sheet,
    then the range of hidden is from row 9 to last row - 25.

    If Application.IsNA(Application.Match(ws1.Range("B6").Value, ws2.Columns(2), 0)) Then   'if it is a new year
            insertR = Application.Match(ws1.Range("B1").Value - 1, ws2.Columns(2))              'find the last row
            ws2.Rows(insertR + 1 & ":" & insertR + 6).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromRightOrBelow    'insert rows
            ws2.Range(9 ":"insertR - 25).EntireRow.Hidden = True  'hide rows
    End If

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,877
    ws2.Range("9:" & insertR - 25).EntireRow.Hidden = True
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •