Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default help with named ranges please

I am having trouble with using named ranges. I want to use them to create
charts in code.
I have

srt = Cells(1, i).Value & "_sort"
cmf = Cells(1, i).Value & "_cumf"
ActiveWorkbook.Names.Add Name:=srt, RefersTo:=Range(Cells(2, 5),
Cells(lastrow, 5))
ActiveWorkbook.Names.Add Name:=cmf, RefersTo:=Range(Cells(2, 7),
Cells(lastrow, 7))

and this set up the named ranges ok. The I want to add a chart:

ActiveChart.ChartType = xlXYScatter
ActiveChart.SetSourceData Source:=Sheets("Data").Range("a1"),
PlotBy:=xlColumns
ActiveChart.SeriesCollection(1).XValues = "'Data'!srt"
ActiveChart.SeriesCollection(1).Values = "'Data'!cmf"

This fails at the last line with "Unable to set the Values property...."
Could someone tell me what the syntax is please and what the difference is
between the last 2 lines, why one works and one doesn't?

Thanks
Chris


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default help with named ranges please

this looks wrong
ActiveChart.SetSourceData Source:=Sheets("Data").Range("a1"),
should be the range of data, so if A1:KK200 is named DataTable
ActiveChart.SetSourceData Source:=Sheets("Data").Range(cmf),

This line
ActiveChart.SeriesCollection(1).XValues = "'Data'!srt"

You don't have a range called "srt"
try
ActiveChart.SeriesCollection(1).XValues =Range(srt)
the last line isn't necessary if you already set the source


Your confusion is that you set variables to the range, then try to hard code
the name

text = "abc"

Range("text") is incorrect
Range("abc") is correct
Range(text) is correct





"inquirer" wrote:

I am having trouble with using named ranges. I want to use them to create
charts in code.
I have

srt = Cells(1, i).Value & "_sort"
cmf = Cells(1, i).Value & "_cumf"
ActiveWorkbook.Names.Add Name:=srt, RefersTo:=Range(Cells(2, 5),
Cells(lastrow, 5))
ActiveWorkbook.Names.Add Name:=cmf, RefersTo:=Range(Cells(2, 7),
Cells(lastrow, 7))

and this set up the named ranges ok. The I want to add a chart:

ActiveChart.ChartType = xlXYScatter
ActiveChart.SetSourceData Source:=Sheets("Data").Range("a1"),
PlotBy:=xlColumns
ActiveChart.SeriesCollection(1).XValues = "'Data'!srt"
ActiveChart.SeriesCollection(1).Values = "'Data'!cmf"

This fails at the last line with "Unable to set the Values property...."
Could someone tell me what the syntax is please and what the difference is
between the last 2 lines, why one works and one doesn't?

Thanks
Chris



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default help with named ranges please

not sure if my reply got there. here's a shorter version anyway

you are not using the variable correctly

To use a range named "ABC"

text = "abc" or text = Range("C1") & "_abc" is good

Range("abc") is good
range(text) is good
Range("text") is bad..there's no range named "text", text is the variable

so
ActiveChart.SeriesCollection(1).XValues = "'Data'!srt"
is BAD
ActiveChart.SeriesCollection(1).XValues = Range(srt)

you don't need the last line you set the data source correctly
ActiveChart.SetSourceData Source:=Sheets("Data").Range("a1"),
ActiveChart.SetSourceData Source:=Sheets("Data").Range("datatable")
or
text = "datatable"
ActiveChart.SetSourceData Source:=Sheets("Data").Range(text),




"inquirer" wrote:

I am having trouble with using named ranges. I want to use them to create
charts in code.
I have

srt = Cells(1, i).Value & "_sort"
cmf = Cells(1, i).Value & "_cumf"
ActiveWorkbook.Names.Add Name:=srt, RefersTo:=Range(Cells(2, 5),
Cells(lastrow, 5))
ActiveWorkbook.Names.Add Name:=cmf, RefersTo:=Range(Cells(2, 7),
Cells(lastrow, 7))

and this set up the named ranges ok. The I want to add a chart:

ActiveChart.ChartType = xlXYScatter
ActiveChart.SetSourceData Source:=Sheets("Data").Range("a1"),
PlotBy:=xlColumns
ActiveChart.SeriesCollection(1).XValues = "'Data'!srt"
ActiveChart.SeriesCollection(1).Values = "'Data'!cmf"

This fails at the last line with "Unable to set the Values property...."
Could someone tell me what the syntax is please and what the difference is
between the last 2 lines, why one works and one doesn't?

Thanks
Chris



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default help with named ranges please

Thanks for your replies, I think I have it under control now
Chris

"Patrick Molloy" wrote in message
...
not sure if my reply got there. here's a shorter version anyway

you are not using the variable correctly

To use a range named "ABC"

text = "abc" or text = Range("C1") & "_abc" is good

Range("abc") is good
range(text) is good
Range("text") is bad..there's no range named "text", text is the variable

so
ActiveChart.SeriesCollection(1).XValues = "'Data'!srt"
is BAD
ActiveChart.SeriesCollection(1).XValues = Range(srt)

you don't need the last line you set the data source correctly
ActiveChart.SetSourceData Source:=Sheets("Data").Range("a1"),
ActiveChart.SetSourceData Source:=Sheets("Data").Range("datatable")
or
text = "datatable"
ActiveChart.SetSourceData Source:=Sheets("Data").Range(text),




"inquirer" wrote:

I am having trouble with using named ranges. I want to use them to create
charts in code.
I have

srt = Cells(1, i).Value & "_sort"
cmf = Cells(1, i).Value & "_cumf"
ActiveWorkbook.Names.Add Name:=srt, RefersTo:=Range(Cells(2, 5),
Cells(lastrow, 5))
ActiveWorkbook.Names.Add Name:=cmf, RefersTo:=Range(Cells(2, 7),
Cells(lastrow, 7))

and this set up the named ranges ok. The I want to add a chart:

ActiveChart.ChartType = xlXYScatter
ActiveChart.SetSourceData Source:=Sheets("Data").Range("a1"),
PlotBy:=xlColumns
ActiveChart.SeriesCollection(1).XValues = "'Data'!srt"
ActiveChart.SeriesCollection(1).Values = "'Data'!cmf"

This fails at the last line with "Unable to set the Values property...."
Could someone tell me what the syntax is please and what the difference
is
between the last 2 lines, why one works and one doesn't?

Thanks
Chris





Reply
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
Like 123, allow named ranges, and print named ranges WP Excel Discussion (Misc queries) 1 April 8th 05 06:07 PM
Named Ranges Gary T Excel Worksheet Functions 2 December 27th 04 02:28 AM
Named Ranges Marie Excel Programming 2 August 5th 04 09:55 PM
named ranges - changing ranges with month selected gr8guy Excel Programming 2 May 28th 04 04:50 AM
Named Ranges and VBA Add-ins Tom Ogilvy Excel Programming 0 September 4th 03 09:58 PM


All times are GMT +1. The time now is 04:28 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"