Relative references and macro programming
Hi Ruth,
Try something like:
'===========
Sub Tester()
Dim rng As Range
Set rng = ActiveCell.Resize(143)
Charts.Add
With ActiveChart
.ChartType = xlLine
.SetSourceData Source:=rng, PlotBy:=xlColumns
.Location Whe=xlLocationAsNewSheet
.HasTitle = False
.Axes(xlCategory, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = False
End With
End Sub
'<<===========
---
Regards,
Norman
"Ruth" wrote in message
ups.com...
I am trying to use a macro to make a line graph of certain cells within
my worksheet (Excel 2004:mac). The data will always be 143 rows. I
want to be able to select the starting cell, and have the macro
automatically select the 142 rows below it and create a line graph. I
have tried using relative referencing within my macro, but the graph
that is created always results in my original selected data being
graphed. I made sure relative referencing is selected. What am I
doing wrong?
This is the code that is generated from my macro:
Sub Macro4()
ActiveCell.Range("A1:A143").Select
Charts.Add
ActiveChart.ChartType = xlLine
ActiveChart.SetSourceData Source:=Sheets("data").Range("G79:G221"),
PlotBy _
:=xlColumns
ActiveChart.Location Whe=xlLocationAsNewSheet
With ActiveChart
.HasTitle = False
.Axes(xlCategory, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = False
End With
End Sub
I found an earlier thread that talked about this same situation but I
could not get it to work. This was the code that was suggested:
Sub Macro1()
Dim r As Range
Dim s As String
Set r = ActiveCell.Resize(10,0)
s = ActiveCell.Parent.Name
Charts.Add
ActiveChart.ChartType = xlLineMarkersStacked
ActiveChart.SetSourceData Source:=r
ActiveChart.Location Whe=xlLocationAsObject, Name:=s
End Sub
I got a syntax error when trying this out...
Thanks for the help.
|