PC Review


Reply
Thread Tools Rate Thread

Check if Date within this week/last week

 
 
Duncan
Guest
Posts: n/a
 
      15th Dec 2006
Hi All,

I am having trouble figuring out a way to go through a range and
determine if each cells date content was this week or last week etc,
What I have so far looks if it is equal to today but I want to change
it so it looks if the date is coming up within a week and I will have a
seperate button to see if it was within last week.

I have so far:

For Each cl In Range("D11000")
If cl.Value = Date Then
MsgBox "Description = " & cl.Offset(0, -3).Value & vbCrLf &
"Location = " & cl.Offset(0, -2).Value & vbCrLf & "Date of Next Test =
" & cl.Value, vbCritical + vbExclamation
End If
Next
End Sub


Now the above works perfectly, but I dont have a clue how I would now
go on to say is the date (cl.value) coming up in seven days time?

Any help at all would be much appreciated.

Many thanks

Duncan

 
Reply With Quote
 
 
 
 
Nik
Guest
Posts: n/a
 
      15th Dec 2006
Duncan wrote:
>
> For Each cl In Range("D11000")
> If cl.Value = Date Then


> Now the above works perfectly, but I dont have a clue how I would now
> go on to say is the date (cl.value) coming up in seven days time?
>


Excel stores dates as numbers, and a day is equal to '1'. Forward time
= larger numbers

So, saying "cl.value is less than 7 days from now" is exporessed as

if cl.value < date + 7

this will also find all dates in the past, which we may not want. 'In
the next week' becomes
if cl.value < date + 7 and cl.value <= date

HTH, post back if not.

Nik
 
Reply With Quote
 
Duncan
Guest
Posts: n/a
 
      15th Dec 2006
Hi Nik,

Thank you, that does work to a fashion but also brings back ones where
the date is previous to today, I tried reversing the "<" to ">" but
didnt seem to work

I will play about with it.......


Nik wrote:
> Duncan wrote:
> >
> > For Each cl In Range("D11000")
> > If cl.Value = Date Then

>
> > Now the above works perfectly, but I dont have a clue how I would now
> > go on to say is the date (cl.value) coming up in seven days time?
> >

>
> Excel stores dates as numbers, and a day is equal to '1'. Forward time
> = larger numbers
>
> So, saying "cl.value is less than 7 days from now" is exporessed as
>
> if cl.value < date + 7
>
> this will also find all dates in the past, which we may not want. 'In
> the next week' becomes
> if cl.value < date + 7 and cl.value <= date
>
> HTH, post back if not.
>
> Nik


 
Reply With Quote
 
Duncan
Guest
Posts: n/a
 
      15th Dec 2006
Hi Nik,

Have got it working with your post, I was being slightly dim earlier!

For all of this weeks I have got:
if cl.value < date + 7 and cl.value >= date

For all of last weeks I have got
if cl.value > date - 7 and cl.value < date

Duncan wrote:
> Hi Nik,
>
> Thank you, that does work to a fashion but also brings back ones where
> the date is previous to today, I tried reversing the "<" to ">" but
> didnt seem to work
>
> I will play about with it.......
>
>
> Nik wrote:
> > Duncan wrote:
> > >
> > > For Each cl In Range("D11000")
> > > If cl.Value = Date Then

> >
> > > Now the above works perfectly, but I dont have a clue how I would now
> > > go on to say is the date (cl.value) coming up in seven days time?
> > >

> >
> > Excel stores dates as numbers, and a day is equal to '1'. Forward time
> > = larger numbers
> >
> > So, saying "cl.value is less than 7 days from now" is exporessed as
> >
> > if cl.value < date + 7
> >
> > this will also find all dates in the past, which we may not want. 'In
> > the next week' becomes
> > if cl.value < date + 7 and cl.value <= date
> >
> > HTH, post back if not.
> >
> > Nik


 
Reply With Quote
 
Nik
Guest
Posts: n/a
 
      15th Dec 2006
Duncan wrote:
>>
>>this will also find all dates in the past, which we may not want. 'In
>>the next week' becomes
>>if cl.value < date + 7 and cl.value <= date
>>

>
> Thank you, that does work to a fashion but also brings back ones where
> the date is previous to today, I tried reversing the "<" to ">" but
> didnt seem to work
>

Sorry, my mistake.

Try playing with changing the <= to >= - this will restrict to dates
today or future. Combined with < date + 7, this gives you what you want.

Nik
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert regular Date to Week Ending or Week Beginning Dates Sam H Microsoft Excel Misc 4 27th Jan 2010 03:27 PM
Convert today's date -7 days to week YYYYWW (last week) AFSSkier Microsoft Access Queries 4 26th Nov 2008 09:09 PM
Reports: Group with date by week - Can I change start of week to M Luc Barrette Microsoft Access Forms 2 29th Feb 2008 11:32 AM
Finding a week number from a given date - Custom Defined Week Numb =?Utf-8?B?V2VuZHk=?= Microsoft Access Form Coding 3 14th Feb 2005 10:49 PM
I need week number in excell from a date, first week must be mini. =?Utf-8?B?alBlaWNo?= Microsoft Excel Misc 4 5th Jan 2005 01:21 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:28 AM.