Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting range for charts

Status
Not open for further replies.

swamit

Technical User
Jan 9, 2002
16
US
I have 2 questions really - Once I draw a chart, how can I delete it thru the macro ? - a new one is drawn continuously and hence I need the old one to be deleted....

Second question....
I want to draw a line chart thru a macro - the data for the chart is sometimes 10 rows, sometimes 20...
Column C contains data that changes with time...
So I am using this to find out how many lines of data do I have for the chart

Range("AA1").Value = "=Count(C:C) + 1"

So I get a number that tells me how many rows of data I have....say the above line returns 20...Then concatenate that with letter C...and get "C20" - and lets say I store this value in cell AA2...so when I draw my chart, I should be able to do this (look at the range object)

Charts.Add
ActiveChart.ChartType = xlLineMarkersStacked
ActiveChart.SetSourceData Source:=Workbooks("New.xls").Sheets("Sheet1").Range("C1:AA2"), PlotBy:=xlColumns

Now here I used AA2 in my range since my range is ever-changing....It doesnt like that...I tried this and some other things but am baffled by the intricate stuff that I did myself....
Please help !!!
 
Hi,
As far as deleting charts...
1. Specific charts either by Name or Index, ie
Code:
ActiveWorkbook.Chart(2).Delete
2. To delete all charts
Code:
    For Each Chart In ActiveWorkbook.Charts
        Chart.Delete
    Next

To create a chart pointing to a variable range, see my FAQ regarding renaming ranges. Use a named range such as "SourceData", as explained and then...
Code:
    Charts.Add
    With ActiveChart
        .ChartType = xlLineMarkersStacked
        .SetSourceData _
            Source:=[SourceData], _
            PlotBy:=xlColumns
    End With
Hope this helps :) Skip,
metzgsk@voughtaircraft.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top