setting source data

cjsmith22

New Member
Joined
Nov 2, 2005
Messages
22
having a bit of trouble setting up a chart in my macro - the worksheet has been assigned to the variable mynewSheet and the data for the chart is in a range called mynewTable (inside mynewSheet). I need whats in column A (a list of team names)to go across the horizontal and column O(number of goals scored) to be the vertical.
tried something like the following which didnt work

Code:
Charts.Add
ActiveChart.ChartType = xl3DColumnStacked
ActiveChart.SetSourceData _
    Source:=mynewSheet(mynewTable.Range("A:0"))
ActiveChart.Location xlLocationAsObject, Name:="chartdata"
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
cj.

this worked for me:

Code:
Sub CreateChart()
    
    Dim mynewSheet As Worksheet
    Dim mynewTable As Range
    
    Set mynewSheet = ActiveSheet
    Set mynewTable = Union(mynewSheet.Range("A14:A18"), mynewSheet.Range("O14:O18"))
    
    Charts.Add
    ActiveChart.ChartType = xl3DColumnStacked
    ActiveChart.SetSourceData Source:=mynewTable, PlotBy:= _
        xlColumns
    ActiveChart.Location Where:=xlLocationAsObject, Name:=mynewSheet.Name
    ActiveChart.Legend.Delete
End Sub
since you have declared your mynewTable range, no need to reference the worksheet. also, not sure why you are using a relative range reference...aren't you being redundant?

hope this helps. ben.
 
Upvote 0
cheers ben - why is it this line works
Code:
Set mynewTablec = Union(mynewSheet.Range("A1:A20"), f.Range("O1:O20"))


but this doesn't ?
Code:
Set mynewTablec = Union(mynewSheet.Range(A:A), f.Range(O:O))

(so that instead of using rows 1-20 of A and O it uses however many cells are in column A and O of mynewSheet)
 
Upvote 0

Forum statistics

Threads
1,224,885
Messages
6,181,586
Members
453,055
Latest member
cope7895

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