Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default VBA Code to name a variable range

Hi,

I have a macro to create charts. Problem is that the source data is variable
by lenght....could be between 10-15 rows. Columns are always constant.

I can't use the code
ActiveWorkbook.Names.Add Name:="RangeName", RefersTo:=Selection
because you have to specify the cell refs.

Any ideas please?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,942
Default VBA Code to name a variable range

hi,
assumeing that your source data in a A1 down......
the key would be to select the variable range first. try something like
this....
Sub macSetRName()
Sheets("YourSheet").Select
Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
ActiveWorkbook.Names.Add Name:="TheRangeName", RefersTo:=Selection
End Sub
Post back if this don't work for you.

FSt1

"John" wrote:

Hi,

I have a macro to create charts. Problem is that the source data is variable
by lenght....could be between 10-15 rows. Columns are always constant.

I can't use the code
ActiveWorkbook.Names.Add Name:="RangeName", RefersTo:=Selection
because you have to specify the cell refs.

Any ideas please?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default VBA Code to name a variable range

You could use similar to this...

ActiveWorkbook.Names.Add Name:="RangeName", _
RefersTo:=Sheet1.Range("A1", Sheet1.Range("D65536").End(xlUp))
--
HTH...

Jim Thomlinson


"John" wrote:

Hi,

I have a macro to create charts. Problem is that the source data is variable
by lenght....could be between 10-15 rows. Columns are always constant.

I can't use the code
ActiveWorkbook.Names.Add Name:="RangeName", RefersTo:=Selection
because you have to specify the cell refs.

Any ideas please?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default VBA Code to name a variable range

Alternative

Worksheets("Sheet1").Range("D1").Resize(Cells(Rows .Count,"D").End(xlUp).Row)
.. _
Name = "RangeName"


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Jim Thomlinson" wrote in message
...
You could use similar to this...

ActiveWorkbook.Names.Add Name:="RangeName", _
RefersTo:=Sheet1.Range("A1", Sheet1.Range("D65536").End(xlUp))
--
HTH...

Jim Thomlinson


"John" wrote:

Hi,

I have a macro to create charts. Problem is that the source data is

variable
by lenght....could be between 10-15 rows. Columns are always constant.

I can't use the code
ActiveWorkbook.Names.Add Name:="RangeName", RefersTo:=Selection
because you have to specify the cell refs.

Any ideas please?



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default VBA Code to name a variable range

This is spot on
Cheers
John

"FSt1" wrote:

hi,
assumeing that your source data in a A1 down......
the key would be to select the variable range first. try something like
this....
Sub macSetRName()
Sheets("YourSheet").Select
Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
ActiveWorkbook.Names.Add Name:="TheRangeName", RefersTo:=Selection
End Sub
Post back if this don't work for you.

FSt1

"John" wrote:

Hi,

I have a macro to create charts. Problem is that the source data is variable
by lenght....could be between 10-15 rows. Columns are always constant.

I can't use the code
ActiveWorkbook.Names.Add Name:="RangeName", RefersTo:=Selection
because you have to specify the cell refs.

Any ideas please?



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 146
Default VBA Code to name a variable range

Selection.Name = "TheRangeName"

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com/
_______


FSt1 wrote:

hi,
assumeing that your source data in a A1 down......
the key would be to select the variable range first. try something like
this....
Sub macSetRName()
Sheets("YourSheet").Select
Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
ActiveWorkbook.Names.Add Name:="TheRangeName", RefersTo:=Selection
End Sub
Post back if this don't work for you.

FSt1

"John" wrote:


Hi,

I have a macro to create charts. Problem is that the source data is variable
by lenght....could be between 10-15 rows. Columns are always constant.

I can't use the code
ActiveWorkbook.Names.Add Name:="RangeName", RefersTo:=Selection
because you have to specify the cell refs.

Any ideas please?

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
can i link a variable cost code with a variable sum I need help!! Excel Discussion (Misc queries) 0 August 1st 08 11:40 AM
how do I hard code a variable range for a pivot table in vba? havocdragon Excel Programming 1 June 29th 05 10:21 PM
variable code Paul Excel Programming 2 April 5th 05 05:27 PM
setting a range variable equal to the value of a string variable Pilgrim Excel Programming 2 July 1st 04 11:32 PM
Problem trying to us a range variable as an array variable TBA[_2_] Excel Programming 4 September 27th 03 02:56 PM


All times are GMT +1. The time now is 05:52 AM.

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

About Us

"It's about Microsoft Excel"