Need help with VBA to populate a chart...

Lidsavr

Active Member
Joined
Jan 10, 2008
Messages
330
I am using Excel 2007, but my code is sometimes run by users with Excel 2003.

I am trying to create a chart in a worksheet (I believe this is called a ChartObject). My code DOES create a chart, but it is blank. I need to figure out how to populate the chart with data the data found in the first four rows of the code.

I have tried everything I can think of, including reading Jon Peltier's dynamic charting instructions (which seems to be over my head).

Here is my code:

Code:
    Range("A37").Select
    r = Range("A37").End(xlDown).Row
    c = Range("A37").End(xlToRight).Column
    Range(Range("A37"), Cells(r, c)).Select
    
    Dim cht1 As ChartObject
    Set cht1 = ActiveSheet.ChartObjects.Add(100, 100, 720, 370.08)
    
'    cht1.Chart.ChartWizard ActiveSheet.Range(Selection), Gallery:=xlColumnCluster, _
            PlotBy:=xlRows, HasLegend:=True, Title:=drng
    
    Sheets("232 Data").Select
    ActiveSheet.ChartObjects(1).Select False
    Selection.Cut
    Sheets("232 Charts").Select
    Range("A3").Select
    ActiveSheet.Paste
    CutCopyMode = False
    Worksheets("232 Charts").Select
    ActiveSheet.ChartObjects(1).Select False

I have one line of code commented out using '. This is because this line of code gives me an error. I believe it is because of the Range(Selection) portion of the line. What I wanted this line of code to do is use the ChartWizard and use the first four lines of code (which selects the table of data) as the Range.

Can anyone help me figure out how to populate the chart and/or fix my code?

Thanks,

Lidsavr
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Forum statistics

Threads
1,224,567
Messages
6,179,571
Members
452,927
Latest member
whitfieldcraig

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