Macro for creating charts

livvi_77

New Member
Joined
Aug 8, 2011
Messages
6
So have the basic VBA but its not working. Currently its highlighting the last five lines and saying that its expecting an end of statement. Any help would be greatly appreciated. Thanks :)


Sheets("Sheet3").Select
' Select the cell in the upper-left corner of the chart.
Range("b2").Select
' Select the current range of data. This line of code assumes that
' the current region of cells is contiguous - without empty rows
' or columns.
Selection.CurrentRegion.Select
' Assign the address of the selected range of cells to a variable.
myrange = Selection.Address
' Assign the name of the active sheet to a variable. This line is
' used in order to allow a chart to be created on a separate chart
' sheet.
mysheetname = ActiveSheet.Name
' Add a chart to the active sheet.
' ActiveSheet.ChartObjects.Add(125.25, 60, 301.5, 155.25).Select
' To create a chart on a separate chart sheet, remark out the
' previous line, and substitute the next line for the one above.
Charts.Add
Application.CutCopyMode = False
ActiveChart.ChartType = x1ColumnClustered
ActiveChart.SetSourceData Source:=Sheets(mysheetname).Range(myrange), _
PlotBy:=xlColumns, _
CategoryLabels:=1, SeriesLabels:=1 HasLegend:=0,
Title:="", CategoryTitle:="", _
ValueTitle:="", ExtraTitle:=""

Just to clarify trying to get it to make a chart with whatever data is in the sheet.
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Since it's all part of one statement, all the lines bar the last should terminate with a space and an underscore, to tell vb you've not finished.

Code:
CategoryLabels:=1, SeriesLabels:=1 HasLegend:=0,
doesn't appear to have this format.
 
Upvote 0
Thanks Weaver. Also realised the commands I was using weren't available in excel 2003 which was creaing issues. Thanks for all your help :)
 
Upvote 0

Forum statistics

Threads
1,215,212
Messages
6,123,655
Members
449,113
Latest member
Hochanz

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