Macro to calculate dates between two color range in gantt chart

harry1805

New Member
Joined
Feb 23, 2012
Messages
18
Hi,

I need help in calculating start and finish date in a gantt chart color range. I have a excel with some data and gantt chart with color range between dates. I wanted a macro which show me the start and finish between a gantt chart color range.

Attaching screenshot.

Thanks
 

Attachments

  • excel help.PNG
    excel help.PNG
    8.2 KB · Views: 15

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
I assume that the coloured cells have been coloured manually?
You could try this in a copy of your workbook.

VBA Code:
Sub TaskDuration()
  Dim rMonthHeaders As Range, c As Range, rStart As Range, rEnd As Range
 
  Set rMonthHeaders = Range("F1:Q1")  '<- edit to suit your data
  Application.FindFormat.Clear
  Application.FindFormat.Interior.Color = RGB(0, 176, 240)  '<- Edit to match your cell colour RGB value
  For Each c In Range("A2", Range("A" & Rows.Count).End(xlUp))
    With Intersect(c.EntireRow, rMonthHeaders.EntireColumn)
      Set rStart = .Find(What:="", After:=.Cells(.Cells.Count), SearchDirection:=xlNext, SearchFormat:=True)
      If Not rStart Is Nothing Then
        c.Offset(, 1).Value = Intersect(rStart.EntireColumn, rMonthHeaders).Value
        Set rEnd = .Find(What:="", After:=rStart, SearchDirection:=xlPrevious, SearchFormat:=True)
        c.Offset(, 2).Value = Intersect(rEnd.EntireColumn, rMonthHeaders).Value
        c.Offset(, 3).Value = rEnd.Column - rStart.Column + 1
      End If
    End With
  Next c
  Application.FindFormat.Clear
End Sub

Here is my test sheet after the code has been run. It produced the values in B2:D7
If this is not what you wanted, please clarify.

harry1805 2020-02-09.xlsm
ABCDEFGHIJKLMNOPQ
1TaskStartEndDurationJanFebMarAprMayJunJulAugSepOctNovDec
2task1MarJun4
3task2AprJul4
4task3AugNov4
5task4
6task5AprJun3
7task6JanJan1
Sheet1
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,191
Members
452,616
Latest member
intern444

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top