A macro that will hide all but the last 20 dated rows.

M

Mac0001UK

I have a spreadsheet where the leftmost column is dates in ascending order. I
want to write a macro that will hide all but the last 20 dated rows. Cany
anybody help please.
 
J

Jarek Kujawa

in Excel 2003

Sub hide()
Dim counter As Integer

ActiveSheet.Range("A65536").Select
Selection.End(xlUp).Select
For i = 1 To Selection.Row
If Len(Selection) > 0 And IsDate(Selection) Then
counter = counter + 1
If counter <= 2 Then
Selection.Rows.EntireRow.Hidden = True
Else
Exit For
End If
End If
Selection.Offset(-1, 0).Select
Next i
End Sub

for Excel 2007 adjust the "ActiveSheet.Range("A65536").Select" row
accordingly

HIH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top