RANGE DATE CODE

  • Thread starter Thread starter tkraju via OfficeKB.com
  • Start date Start date
T

tkraju via OfficeKB.com

I have date range in Col A:A.I need code that selects A2 to 3 months back
date from today.
Suppose 3 months back date is 9 th Dec 2006 and it exists in A15 cell ,the
range to select
is A2:A15.What code will give this result.Thanks for any help in this regard.
 
tkraju said:
I have date range in Col A:A.I need code that selects A2 to 3 months back
date from today.
Suppose 3 months back date is 9 th Dec 2006 and it exists in A15 cell ,the
range to select
is A2:A15.What code will give this result.Thanks for any help in this regard.

Assuming the dates are in descending order and there are no blanks in your
list of dates, this will select the range from A1 to the last cell with a
date greater than Now() - 30 (days):
=================
Sub dates()

Dim MyDatesList As Range
Set MyDatesList = Worksheets("Sheet1").Range("A1", _
Worksheets("Sheet1").Range("A2").End(xlDown))

For Each dt In MyDatesList
If dt.Value > Now() - 30 Then
Worksheets("Sheet1").Range("A1", dt).Select
Else
End If

Next dt

End Sub
==================
 
Thanks,McBain,but my dates in range A:A are in ascending order and no blanks,
holidays excluded.
will this code takes care of this.
 
tkraju said:
Thanks,McBain,but my dates in range A:A are in ascending order and no blanks,
holidays excluded.
will this code takes care of this.

It will select from A1 down to the farthest date down the list that
satisfies the driteria ie now() - 30 or whatever you choose.
 
Many thanks,I substituted '>' with '<' ,my ascending order range given
correct results.
Thank you once again.

Damien said:
Thanks,McBain,but my dates in range A:A are in ascending order and no blanks,
holidays excluded.
will this code takes care of this.

It will select from A1 down to the farthest date down the list that
satisfies the driteria ie now() - 30 or whatever you choose.
I have date range in Col A:A.I need code that selects A2 to 3 months back
date from today. [quoted text clipped - 22 lines]
End Sub
==================
 
tkraju said:
Many thanks,I substituted '>' with '<' ,my ascending order range given
correct results.
Thank you once again.

No worries. Remember to read the group for a while after receiving some
help and see if you can offer some as well - this keeps it free for all of
us :)
 

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

Back
Top