Thread: Macro
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein \(MVP - VB\)[_1421_] Rick Rothstein \(MVP - VB\)[_1421_] is offline
external usenet poster
 
Posts: 1
Default Macro

Here is some code to do that...

Sub GanttChart()
Dim X As Long
Dim LastRow As Long
Dim Start As Range
Dim Finish As Range
With Worksheets("Sheet3")
Range("D2:O999").ClearFormats
LastRow = .Cells(Rows.Count, 1).End(xlUp).Row
For X = 2 To LastRow
Set Start = Cells(X, 3 + Month(.Range("B" & X).Value & " 1, 2000"))
Set Finish = Cells(X, 3 + Month(.Range("C" & X).Value & " 1, 2000"))
Range(Start, Finish).Cells.Interior.Color = RGB(172, 172, 172)
Next
End With
End Sub

I used a gray color instead of black, but you can change the color on a per
row basis via the RGB function call if you want. Also, the code works based
on 3-letter month abbreviations in Columns B and C as well as in your
headers; if you want something different, let me know and I'll modify the
code to account for it.

Rick


"CMD" wrote in message
...
Hi. I am trying to mimic some MS Project functionality in Excel. I want
to
try and automate the creation of a basic gantt chart. Is there a way I
can
do the following:

Columns D - O are labeled months of the year. Column A is a task, column
B
is a start month and column C is a stop month. I would like to set it up
such that once the user puts in a start/stop month, that the respective
cells
(and everything in between) gets shaded a certain color.

So for example if I have a task of develop software in row 2 and the start
stop is Feb/Apr, I would like cells E2, F2 and G2 to be shaded black.

Thanks in advance.

Chris