Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50061

Choosing chart range.

$
0
0
Hi!

I am creating a chart and I want the user to be able to select the data range rows before a chart is automatically created. It would be better if the user didn't have to go into VBA to change the range.
I've pasted my code below. I'm getting a 1004 error: Method 'Range' of object '_Global' failed, at the * marked line.

My questions are:
1) How can I create and use a range that would automatically include all the rows for a column? In the sense of xlDown, where it goes down until there is an empty cell.
2) Can I have the user input row numbers (ex: from row 2 to row 6) and create the chart that way?

Thank you!
Code:

Dim ws  As Worksheet
Dim QaScore As Range
    Set QaScore = Range("$B$1:$B$7,$D$1:$D$7,$R$1:$R$7")
*  ws.Range("QaScore").Select
    Range("R1").Activate
    ActiveSheet.Shapes.AddChart.Select
    ActiveChart.ChartType = xlLine
    ActiveChart.SetSourceData Source:=Range("QaScore")    ActiveChart.Parent.Cut
    Range("A9").Select
    ActiveSheet.Paste
    ActiveChart.SetElement (msoElementChartTitleAboveChart)
    Selection.Caption = "QA Score"
    ActiveChart.SeriesCollection(2).Select
    With Selection.Format.Line
        .Visible = msoTrue
        .DashStyle = msoLineSysDot
    End With


Viewing all articles
Browse latest Browse all 50061

Trending Articles