Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Date Comparison | Excel Worksheet Functions | |||
Make table query will work in datasheet view but will not make tab | Excel Discussion (Misc queries) | |||
date comparison help | Excel Discussion (Misc queries) | |||
Date comparison | Excel Discussion (Misc queries) | |||
Spin button in a work sheet - how do I make it work? | Excel Worksheet Functions |