My macro builds a bar chart from data in A5:B and F5:F. The horizontal labels are in A and the values to be charted against the vertical column are in B and F. My code worked fine until a co-worker's dataset only had 2 data points (so the chart covered A5:B6 and F5:F6) and then things flipped. I'm not sure if the 2 data points is the problem but it's the only thing I can think of that changed. My code is below. GrandTotal was previously defined as the last row containing data (the size of this chart changes day to day).
I either need to understand why this is happening and how to stop it or a way to check to see if it has so I can have the macro switch things back to where they should be.
VBA Code:
Set rngAB = ActiveSheet.Range("A5:B" & GrandTotal)
Set rngF = ActiveSheet.Range("F5:F" & GrandTotal)
Set rngChart = Union(rngAB, rngF)
rngChart.Select
ActiveSheet.Shapes.AddChart2(201, xlColumnClustered).Select
Set chtobj = Selection
With chtobj
.Top = Range("H1").Top
.Left = Range("H1").Left
.Width = 700
.Height = 300
End With
I either need to understand why this is happening and how to stop it or a way to check to see if it has so I can have the macro switch things back to where they should be.