LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ed Ed is offline
external usenet poster
 
Posts: 65
Default Need help to make date comparison work, please?

I have a start date and an end date on one worksheet. These cells are
formatted as Date, dd-mmm-yyyy. Across the top of a second worksheet,
I have in B1 the formula =NOW() formatted as Custom, mmm-yy, then from
C1 across several columns is a formula that adds 30 to the previous
cell (C1 is = B1 + 30; D1 is = C1 + 30, etc.).

I am trying to get a macro to compare the month and year across the
top with the start and end dates to set a value in the cell being
looked at. Here's what I've got:

-- cll2 is the cell being looked at
-- dtStart and dtEnd are the start and end dates from the previous
worksheet
(for testing, it's 25 Jun 2007 and 1 Sep 2008)
-- (wks.Cells(1, cll2.Column)) is the cell in Row 1 with the month and
date displayed from the formula
(for testing, it's Jun-07 in B1, Jul-07 in C1, etc to Jul-08 in O1)

This code:

If Month(wks.Cells(1, cll2.Column)) = Month(dtStart) And _
Year(wks.Cells(1, cll2.Column)) = Year(dtStart) Then

If Month(wks.Cells(1, cll2.Column)) <= Month(dtEnd) And _
Year(wks.Cells(1, cll2.Column)) <= Year(dtEnd) Then

produced a good value in columns B (Jun 07), C (Jul 07), D (Aug 07),
and E (Sep 07), then bad values until N (Jun 08) and O (Jul 08).

How can I make this date comparison work?
Ed

 
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
Date Comparison Christopher Naveen[_2_] Excel Worksheet Functions 1 August 13th 09 06:01 AM
Make table query will work in datasheet view but will not make tab WildlyHarry Excel Discussion (Misc queries) 0 August 28th 07 03:06 PM
date comparison help CathyZ Excel Discussion (Misc queries) 5 May 4th 06 11:53 AM
Date comparison Jonibenj Excel Discussion (Misc queries) 6 October 23rd 05 08:34 PM
Spin button in a work sheet - how do I make it work? [email protected] Excel Worksheet Functions 1 April 7th 05 08:43 PM


All times are GMT +1. The time now is 07:04 PM.

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

About Us

"It's about Microsoft Excel"