PDA

View Full Version : Hide Rows in VBA



Maria95
06-22-2016, 06:38 AM
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

p45cal
06-22-2016, 09:41 AM
ws2.Range("9:" & insertR - 25).EntireRow.Hidden = True