Creating Graph Excel 2007 VBA

thetoad30

New Member
Joined
May 20, 2011
Messages
3
Can anyone please point me to code to create graphs in Excel 2007?

I'm trying to create a graph out of data and then manually tell Excel which X-axis labels and legend labels to use, all via VBA code.

I can get the graph to show up, but the data is wrong and the values in the axis and legends are wrong. At this time I don't have a way to show my code or the data I'm using.

Any and all help is greatly appreciated.
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Charts("Chart1").SeriesCollection(1).Name = "=Sheet1!$E$4"

where "Sheet1!$E$4" has the data label. Hope this helps.
 
Upvote 0
Charts("Chart1").SeriesCollection(1).Name = "=Sheet1!$E$4"

where "Sheet1!$E$4" has the data label. Hope this helps.

Above was for changing the series title. Try below for Axis title.

Worksheets("sheet1").ChartObjects(1).Activate
With ActiveChart.Axes(xlValue)
.HasTitle = True
With .AxisTitle
.Caption = "Trial"
End With
End With
 
Upvote 0
Thank you for the code.

However, I am trying to get the code to use cells for the axis labels. This way the graph is "dynamic" in the sense that it will label the graph as the data changes, instead of hard-coding it in.

Changing the title of the X-axis is useful, though, so your effort was not in vain.

I'm just not seeing a whole lot of documentation from MSDN/Microsoft, the help file, or the internet for graphing with 2007, and I appreciate your help on all of this.

As a side note, other than the additions like spark lines, is 2010 the same? I might try a search on graphing with that in google if it is.

Thank you.
 
Upvote 0
Charts("Chart1").SeriesCollection(1).Name = "=Sheet1!$E$4"

where "Sheet1!$E$4" has the data label. Hope this helps.

Does this code name the labels? I was re-reading the post and think I might have misiterpreted this code to be the way to get data into the x-axis and not to label that.

Is there also a way to tell Excel what data to use for the xvalues? I tried the xvalues that I found on Google, but it wasn't working and erroring out.

Thank you.
 
Upvote 0

Forum statistics

Threads
1,223,238
Messages
6,170,939
Members
452,368
Latest member
jayp2104

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