Search code examples
excelgraphexcel-2013vba

Dynamic Milestone Trend Analysis Graph needs same y-axis as x-axis in Excel with VBA


After a couple hours of work I come to you guys with this graphing problem. I need to create a Milestone-Trend-Analysis which can be seen on the german wikipedia , though not in the english version.

General Information

In short, the diagram has report dates on the x-axis (for now, on every first of the month, another report is due). The y-axis should mirror the x-axis completely. In length and also the tickmarks. The dates get bigger from the bottom to the top. In my case the x-Axis is on top of the diagram.

Every report consists of a number of "due-dates", one for each assignement in progress. They are the estimated "finishing dates" of that particular assignement.

If the estimated finishing date stays the same in the next report period, the graph for that assignement stays on the same level. If the estimate is earlier, the graph trends down. Normally they go up, since the assignement has some delay :-D

The x-axis needs to be dynamic, since the whole project is basically finished when its last assignement is finished. If one of the assignements is running late, the whole project gets delayed an thus the x-axis needs to be longer/get more ticks. Since the y-Axis mirrors that, it has to change too.

MY PROBLEM

The x-axis has a number of discreet values, since the reports come in every month, or every two weeks. But that does not change. The values for the finishing dates are continuous, since the assignements can be terminated whenever.

That leaves me with the problem of having to cut the y-axis in equal-size chunks, although the months of the year are not equal in size. At least that is, what I think excel forces me to do.

I can assign a max limit and a min limit for the y-axis and I can assign a distance between each main tickmark. Since Excel works with a continous number for each date, the 2014/01/01 would be 41640. And 2015/01/01 is 42005. Since I have 12 month on the x-axis and I need 12 on the y axis, I would have to have the main Ticks at a distance of 30.42 ... which gives me the following Months on my axis

January January March .... December December

Does anyone know an answer for this? Is there a way to have excel make the tickmarks on the y-axis not equal distance?

Any input greatly appreciated.

Kaz


Solution

  • I did not find a way to make Excel have variable tick mark distances. But since I coud not have it that way, I had to make the month equally long.

    This works for me now:

    'calculate the norm for different type of month including Schaltjahr
    Select Case cellMonth
    
            'February
        Case 2
    
            'Schaltjahr and Schaltjahrhundert
            If (cellYear Mod 4 = 0) Or (cellYear Mod 400 = 0) Then
    
                resultDay = (30 / 29) * cellDay
    
            Else
    
                resultDay = (30 / 28) * cellDay
            End If
    
            '31 day months
        Case 1, 3, 5, 7, 8, 10, 12
    
            resultDay = (30 / 31) * cellDay
    
            '30 day months
        Case Else
    
            resultDay = cellDay
    
    End Select
    

    Now I just have to scale the axis to numberOfMonths * 30. It now leaves adjusting the names of the y-Axis, which seems to be a whole different story.

    Kaz