Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Creating a Range and Range Name

I wish I could send my tries, but I really messed them up. So I will have to explain what I am looking for.

What I am trying to do is take a row of data, create a range based on the first cell to the last cell, and name the range based on the data found in a cell. For example:

I start my search from D1. The range name will be based on the date (The value of the cell) found in D1. The range would be created from A1 to the last cell in the row. (The number of cells is not always the same.) This would be repeated there the entire sheet.

I can get the routine to create the range but I am having problems getting it to name it. My code is very long and ugly, I know someone out there can think of a quick and friendly way to do this. Any help will be very appreciated.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Creating a Range and Range Name

Dim cell as Range
Dim rng as Range
for each cell in Range(Cells(1,1),Cells(rows.count,1).End(xlup))
set rng = Range(Cell,Cells(cell.Row,"IV").End(xltoLeft))
' range name will be based on the date
rng.name = "AA" & Format(cell.offset(0,3).Value,"yyyymmdd")
'or
' name the range based on the data found in a cell
' rng.Name = Cell.offset(0,3).Value
Next

When you say from A1 I assume you mean for row 1. If every range is From A1

Dim cell as Range
Dim rng as Range
for each cell in Range(Cells(1,1),Cells(rows.count,1).End(xlup))
set rng = Range(Range("A1"),Cells(cell.Row,"IV").End(xltoLef t))
' range name will be based on the date
rng.name = "AA" & Format(cell.offset(0,3).Value,"yyyymmdd")
'or
' name the range based on the data found in a cell
' rng.Name = Cell.offset(0,3).Value
Next



--
Regards,
Tom Ogilvy

TroyH wrote in message
...
I wish I could send my tries, but I really messed them up. So I will have

to explain what I am looking for.

What I am trying to do is take a row of data, create a range based on the

first cell to the last cell, and name the range based on the data found in a
cell. For example:

I start my search from D1. The range name will be based on the date (The

value of the cell) found in D1. The range would be created from A1 to the
last cell in the row. (The number of cells is not always the same.) This
would be repeated there the entire sheet.

I can get the routine to create the range but I am having problems getting

it to name it. My code is very long and ugly, I know someone out there can
think of a quick and friendly way to do this. Any help will be very
appreciated.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Creating a Range and Range Name

Thanks for the quick reply. This is great.

I ran the code you gave me and it produced an error.
Run-Time error '1004':
That name is not valid.

It comes from the rng.Name = cell.Offset(0, 3).Value code. The value of the cell is a date.

Thanks again for your help.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Creating a Range and Range Name

a short format date isn't a valid name (and most date formats would not be
valid names) -
a name has to start with a character.
a name can't contain spaces.

That is why I suggested code that could handle a date. If you don't want to
append characters at the start,

You could possibly do

rng.Name = format(cell.offset(0,3).Value,"mmmddyyyy")

then you would get a name like jan272004

or
rng.Name = format(cell.offset(0,3).Value,"mmm_dd_yyyy")

jan_27_2004
--
Regards,
Tom Ogilvy



TroyH wrote in message
...
Thanks for the quick reply. This is great.

I ran the code you gave me and it produced an error.
Run-Time error '1004':
That name is not valid.

It comes from the rng.Name = cell.Offset(0, 3).Value code. The value of

the cell is a date.

Thanks again for your help.



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 use named range in data range box when creating pie chart? BJackson Charts and Charting in Excel 2 August 17th 05 05:37 PM
Creating range name for a range selection Mervyn Thomas Excel Programming 1 January 26th 04 05:18 PM
Creating formula range by last name. jane Excel Programming 0 January 22nd 04 07:40 PM
Creating a range Marco Roberto Excel Programming 3 January 22nd 04 06:48 PM
Creating an XL Range on the fly Chris Parker Excel Programming 3 August 19th 03 01:09 PM


All times are GMT +1. The time now is 10:40 AM.

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"