Hide Rows Between Specified Dates

L

LROCCO

Can anyone help with this please?

I have a list of dates in column B1:B20. I would like to the hide
rows that do not fall between the dates inputted by the user.

There are two text boxes for the user to enter the dates in (i.e. FROM
date and TO date). Once the dates have been entered, I would like the
user to click on a command button to hide the relevant rows.

Any help would be much appreciated

Regards

Lui
 
S

Shane Devenshire

Hi,

You might consider showing them the AutoFilter command when you pick Custom
from the resulting dropdown the user can pick Greater than or equal to in the
first box , enter a date in the second one, pick Less than or equal to from
the second drop down and enter the end date in the last box. Only those
records will be displayed.

If you want to automate this even more you can record the above step and
then modify the code depending on where you want them to enter the 2 dates.

If this helps, please click the Yes button

Cheeers,
Shane Devenshire
 
D

Don Guillett

Try this instead where the macro asks for the dates.

Sub hidedates()
Rows.Hidden = False
fd = CDate(InputBox("Enter first date"))
ld = CDate(InputBox("enter last date"))
For i = Cells(Rows.Count, "b").End(xlUp).Row To 2 Step -1
If Cells(i, "b") >= fd And Cells(i, "b") <= ld Then
Rows(i).Hidden = True
End If
Next i
End Sub
 
L

LROCCO

Try this instead where the macro asks for the dates.

Sub hidedates()
Rows.Hidden = False
fd = CDate(InputBox("Enter first date"))
ld = CDate(InputBox("enter last date"))
For i = Cells(Rows.Count, "b").End(xlUp).Row To 2 Step -1
If Cells(i, "b") >= fd And Cells(i, "b") <= ld Then
Rows(i).Hidden = True
End If
Next i
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software








- Show quoted text -

Many thanks for both replies.

Don I used code and it works great.

How do I get it to hide all rows that are not between these dates, but
excluding blanks cells, the first two rows and the two last rows in
use?
 
D

Don Guillett

Please answer at the TOP when posting to me.
Try this.

Sub hidedatesA()
Rows.Hidden = False
fd = CDate(InputBox("Enter first date"))
ld = CDate(InputBox("enter last date"))
For i = 3 To Cells(Rows.Count, "b").End(xlUp).Row - 2
If Cells(i, "b") <> "" Then
If Cells(i, "b") <= fd Or Cells(i, "b") >= ld Then
Rows(i).Hidden = True
End If
End If
Next i
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(e-mail address removed)
Try this instead where the macro asks for the dates.

Sub hidedates()
Rows.Hidden = False
fd = CDate(InputBox("Enter first date"))
ld = CDate(InputBox("enter last date"))
For i = Cells(Rows.Count, "b").End(xlUp).Row To 2 Step -1
If Cells(i, "b") >= fd And Cells(i, "b") <= ld Then
Rows(i).Hidden = True
End If
Next i
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software








- Show quoted text -

Many thanks for both replies.

Don I used code and it works great.

How do I get it to hide all rows that are not between these dates, but
excluding blanks cells, the first two rows and the two last rows in
use?
 

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