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: 12

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
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,215,903
Messages
6,127,651
Members
449,395
Latest member
Perdi

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