Macro switches rows/columns in chart when only 2 data points

akg742

New Member
Joined
Mar 13, 2014
Messages
39
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).

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.
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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