Excel Macro

Permabanned
Joined
3 Dec 2004
Posts
2,304
Location
Sheffield
Hi guys, I need some help writing a macro that will search column U for dates between 1/1/06 and 28/1/06, and hide any cells/rows that arent related to these dates.

Anyhelp would be much apreciated. Cheers
 
This only works on a fixed number of rows and I am sure it could be improved (but I haven't fiddled with VBA for a long time)

Code:
For i = 1 To 100
  If (Range("U" & i).Text < "01/01/06") Or (Range("U" & i).Text > "28/01/06") Then
    Rows(i & ":" & i).Select
    Selection.EntireRow.Hidden = True
  End If
Next i
 
Thanks mate, I found an Excel forum where some guys helped me out, your code is similar to theirs.

Code:
Sub DownSelect()
    Dim c As Range
    For Each c In Range("V1:V" & Cells(Rows.Count, 22).End(xlUp).Row)
        If c < DateSerial(2006, 1, 1) Or c > DateSerial(2006, 1, 28) Then c.EntireRow.Hidden = True
    Next c
End Sub

For future reference.
 
Back
Top Bottom