View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Norman Jones Norman Jones is offline
external usenet poster
 
Posts: 5,302
Default Macro problem. Need a vague not absolute reference

Hi Jeff,

Referring to your line:

Source:=Sheets(Sheetactive).Range(selected), PlotBy



To identify the current sheet , use:

ActiveSheet

and for the selected range, use:

Selection

As Rob Bovey suggested, with your chart plot data selected, you can refer to
the plot range with:
Selection
thus obviating the need to specify different plot ranges for different
charts.

So, incorporating this into your chart code to provide a procedure which
will produce a chart for any selected data, you have somethiing like:

Sub tester()
Dim rng As Range

Set rng = Selection

Charts.Add
ActiveChart.ChartType = xlXYScatter
ActiveChart.SetSourceData Source:=rng, PlotBy:=xlColumns
ActiveChart.Location Whe=xlLocationAsNewSheet
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "Sale Price vs Home Size"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text _
= "Sale Price "
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text _
= "Square Feet "
End With

End Sub

For your information, each full line between
With ActiveChart
and
End With
must have an initial period.


---
Regards,
Norman



"Jeff Whitbey " wrote in
message ...
Thanks, but I am still hitting a problem. It is probably something small
and stupid. As complex problems have more visible solutions.
I tried that a few different ways
ActiveChart.SetSourceData
Source:=Sheets("Sheetactive").Range("selected"), PlotBy
Also with out the quotes like below.
I get an error:
Compile editor:
Expected named paramiter
I also tried saving the macro in a worksheet I could open and paste the
data into but I still need to have a variable range. I also tried using
the file name instead of sheetactive.
This seems the most likely text. Can you see my errors?

ActiveChart.ChartType = xlXYScatter
ActiveChart.SetSourceData
Source:=Sheets(Sheetactive).Range(selected), PlotBy
ActiveChart.Location Whe=xlLocationAsNewSheet
With ActiveChart
HasTitle = True
ChartTitle.Characters.Text = "Sale Price vs Home Size"
Axes(xlCategory, xlPrimary).HasTitle = True
Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Sale
Price"
Axes(xlValue, xlPrimary).HasTitle = True
Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Square
Feet"

Thanks
Jeff Whitbey



---
Message posted from
http://www.ExcelForum.com/