Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Problem with calendar planner date ranges

I'm writing an Excel 2003 macro to generate a calendar planner with
coloured worksheet cells forming horizontal bars that show where a
project falls within the year.

However I can't seem to get the logic right to determine whether a
project's date range falls into any given week's column.

Here's a description of what I have:

Column 1 is a list of projects

Column 2 contains the project start dates (not necessarily Sunday
week-ending dates)

Column 3 contains project end dates (not necessarily Sunday week-ending
dates)

Columns 4 to 55 contain the year's 52 Sunday week-ending dates in the
first row and the cells below these are to be coloured if the project's
date range falls into this week. I want the cell shaded if any part of
the project's date range falls into this week.

Can anyone supply me with the comparisons I need to make in order to
determine if a project's date range overlaps the weekly range for a
column on the planner? Any help would be appreciated since my recent
attempts don't seem to pick the right cells. Thanks very much.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default Problem with calendar planner date ranges



'this code assumes the following
'project1 to project7 run from A2 to A8 nothing else in column A
'Project Start dates run from B2 to B8
'Project End dates run from C2 to C8
'week ending sunday dates run from D1 to BC1
'you can have as many projects as you want
'just add them in column A
'The project name must be Project followed by a number
'for this code to work
'I also range named B2:C2 Project1
'B3:C3 Project2 etc

Sub DoColour()

Dim x As Long
Dim z As Long
Dim weeks As Range
Dim Proj As Range
Dim startDate As Date
Dim endDate As Date
Dim dayStart As Integer
Dim dayEnd As Integer
Dim startSun As Date
Dim endSun As Date
Dim StartCell As Long
Dim EndCell As Long
Dim ColourRange As Range

Set weeks = Range("cal") 'week ending Sunday range D1 :BC1
x = Application.CountA(Range("A:A")) 'no of projects
Set weeks = weeks.Offset(1, 0).Resize(x, weeks.Columns.Count)
'clears existing colours
weeks.Interior.ColorIndex = xlColorIndexNone
Set weeks = Range("cal")

'loop projects
For z = 1 To x
Set Proj = Range("project" & z)
startDate = Proj.Cells(1)
endDate = Proj.Cells(2)
dayStart = Weekday(startDate)
dayEnd = Weekday(endDate)
Select Case dayStart
Case 1
startSun = startDate
Case 2, 3, 4, 5, 6, 7
startSun = startDate + (8 - dayStart)
End Select
Select Case dayEnd
Case 1
endSun = endDate
Case 2, 3, 4, 5, 6, 7
endSun = endDate + (8 - dayEnd)
End Select

StartCell = WorksheetFunction.Match(CLng(startSun), weeks, 0)
EndCell = WorksheetFunction.Match(CLng(endSun), weeks, 0)
Set ColourRange =
Range(weeks.Cells(StartCell),weeks.Cells(EndCell)) .Offset(z, 0)
ColourRange.Interior.ColorIndex = 3 'red
Next

End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Problem with calendar planner date ranges


Thanks very much for your help Phillip - much appreciated.

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
Calendar Formatting Based Upon Multple Date Ranges Garnet Excel Worksheet Functions 1 March 7th 10 09:38 AM
Convert date from Gregorian Calendar to Hijri Calendar H.Alkhodary Excel Discussion (Misc queries) 1 February 21st 09 10:11 AM
How to link an Excel file due date to Outlook calendar date? anok New Users to Excel 0 May 9th 07 09:31 PM
company calendar: start date problem Tim Marsh Excel Programming 2 July 2nd 06 08:12 PM
automate calendar dates on worksheets to make a yearly planner Tom Excel Discussion (Misc queries) 0 March 2nd 06 04:25 PM


All times are GMT +1. The time now is 11:27 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"