LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default Relative reference in macro

How about showing the generated code?

Here's what I got from a simple test (using relative references as you
have):

ActiveCell.Range("A1:B17").Select ' recorded correctly
Charts.Add
ActiveChart.ChartType = xlLineMarkersStacked
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("D9:E25")
ActiveChart.Location Whe=xlLocationAsObject, Name:="Sheet1"

note that the "Source" parameter is not assigned a relative reference
and that the chart location will always be "Sheet1"

Try something like this:

Sub Macro1()

Dim r As Range
Dim s As String
Set r = ActiveCell.Resize(10, 10)
s = ActiveCell.Parent.Name

Charts.Add
ActiveChart.ChartType = xlLineMarkersStacked
ActiveChart.SetSourceData Source:=r
ActiveChart.Location Whe=xlLocationAsObject, Name:=s

End Sub


Tim.


"Ricki Miles" wrote in message
...
I am recording a macro in Excel XP that will select a range of data
and make
a chart. The data will always be ten rows and two columns. Since
the data
may start in different cells on different sheets, I would like the
macro to
be relative so that when I click a starting cell and then run the
macro, it
will select the data starting at the active cell. I have tried
recording by
first activating the starting cell I would like, then Tools, Macro,
Record
New Macro, clicking the relative reference button on the macro
toolbar, then
selecting the range of cells and creating the chart.

When I use this macro in any starting cell, it always charts the
data by
starting at the cell I was at when I recorded the macro. What am I
doing
wrong?

Thanks for the help,

Ricki




 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Relative reference? in macro TRYING Excel Worksheet Functions 3 November 20th 07 12:00 AM
Using relative reference in macro Bas Excel Discussion (Misc queries) 0 March 23rd 06 12:11 PM
Relative Reference in a Macro DRH Excel Programming 2 December 31st 04 02:20 PM
How do I set up a macro using relative cell reference? Vivyans Excel Programming 1 December 9th 04 07:26 PM
MACRO Relative Reference Ibrahim Awwad Excel Programming 3 September 9th 03 02:11 PM


All times are GMT +1. The time now is 05:35 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"