-
Solved: Using named range to plot chart data
I am trying to write code for the Macro to use a named range ("Load" and "Disp") to plot a series onto a chart.
I tried using [vba].Range("E:E")[/vba] but the graph is off because a couple of the cells that get selected have text
with the code below I get the
Run-time error '1004':
Application-defined or object-defined error
where it is in bold.
[vba]
With ActiveSheet
' cell formatting here!
' find last row with data
LastRow = .Range("A65536").End(xlUp).Row
DataStart = FindTime + 2
For x = DataStart To LastRow
' more cell formattting and calclations here!
Next x
Range("E" & DataStart, ActiveCell.End(xlDown)).Name = "Load"
Range("F" & DataStart, ActiveCell.End(xlDown)).Name = "Disp"
End With
' plot chart data for each test specimen
Sheets("SummaryData").Select
ActiveSheet.ChartObjects("Chart 1").Activate
With ActiveChart.SeriesCollection.NewSeries
.Name = WsName
.Values = Sheets(WsName).Range("Load")
.XValues = Sheets(WsName).Range("Disp")
End With
[/vba]
-
I got this figured out, thanks.
-
Can you post your solution for the benefit of others who read this.
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
-
here is how I was able to get it to do what I wanted. Basically told VBA to select the first cell before using the control down function. The way it ran before it was selecting columns A through E which is what was giving me the error. Hope that makes sense.
[vba]Range("E" & DataStart).Select
Range("E" & DataStart, Selection.End(xlDown)).Select
Selection.Name = "Load"
Range("F" & DataStart).Select
Range("F" & DataStart, Selection.End(xlDown)).Select
Selection.Name = "Disp"[/vba]
-
Try to avoid Selection to speed up your code
[VBA]
Dim rng As Range
Set rng = Range("E" & datastart)
Range(rng, rng.End(xlDown)).Name = "Load"
Set rng = Range("F" & datastart)
Range(rng, rng.End(xlDown)).Name = "Disp"
[/VBA]
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
-
Finally got a chance to put this in, Thank you, works great!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules