Hiding certain rows in a worksheet
Posted by Chris Rock on April 24, 2001 1:00 PM
I have a data table that gets updated every week. The most recent data is at the bottom of the table.
It may become necessary to only see the past 20 weeks worth of data, so I'd need to hide any rows that are "older" than 20 weeks.
I used the macro recorder to record a macro to do this, but it won't work. These are the keyboard commands I used when recording the macro:
Ctrl+Home (To bring me to cell A1).
Ctrl+Down Arrow, Ctrl+Down Arrow (to skip to the last row of data).
Up Arrow X 20 (To bring me to the 21st row from the bottom).
Shift+SpaceBar (To highlight the entire 21st row from the bottom).
Ctrl+Shift+Up Arrow (To highlight all the rows from the 21st row up to the Column Headings Row [column A]).
Ctrl+9 (To Hide the rows).
Ctrl+Home (To bring me back to A1).
When I record this as a macro, it doesn't work. This is what the code looks like:
Range ("A1").Select
Selection.End(x1 Down).Select
Selection.End(x1 Down).Select
ActiveCell.Offset(-23,0).Rows(1:4).EntireRow.Select
ActiveCell.Offset(-20,0).Range("A1").Activate
Selection.EntireRow.Hidden = True
Range.("A1").Select
Is there any better way to do this? In my sheet that I used as an example, I had 4 extra rows that I needed to hide, but there may be more or less.
I know very, very little about VBA, but I do understand what is happening in this code. I'd like to be able to write the macro rather than record it.
Can anyone shed some light on this?