Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 290
Default Check if Date within this week/last week

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("D1:D1000")
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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Check if Date within this week/last week

Duncan wrote:

For Each cl In Range("D1:D1000")
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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 290
Default Check if Date within this week/last week

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("D1:D1000")
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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 290
Default Check if Date within this week/last week

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("D1:D1000")
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


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Check if Date within this week/last week

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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert regular Date to Week Ending or Week Beginning Dates Sam H Excel Discussion (Misc queries) 5 April 3rd 23 04:39 PM
Auto calculate day of week to week of the year (not as serial) oftenconfused Excel Discussion (Misc queries) 4 June 23rd 08 05:14 PM
Display "this week" column headers w/date & day of week? Ivan Wiegand Excel Worksheet Functions 9 September 12th 07 05:18 PM
How do I set up a week by week skill training schedule in excel? davidwatts Excel Discussion (Misc queries) 0 June 16th 05 11:32 PM
I need week number in excell from a date, first week must be mini. jPeich Excel Discussion (Misc queries) 4 January 5th 05 01:21 AM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"