Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Create named range

I have a worksheet with rows of data. Col. A contains a
number. I sort the entire list by Col. A then I want to
create a named range for each change in Col. A.

For example, if Cells' A1, A2, and A3 all contain 999,
then I want to take all the Col. A cells with 999 and
create a named range of "999". Then, if Cells' A4, A5,
A6, and A7 all contain 888, then I want to take those 4
cells and create a named range of "888".

Any suggestions on the most efficent way to perform this
task?

Thanks in advance!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default Create named range

First, "999" and "888" are not valid names. You could prefix or
postfix them with a character as I've done he

one way:

Public Sub NameRanges()
Dim cell As Range
Dim firstCell As Range
Set firstCell = Range("A1")
For Each cell In Range(firstCell, _
Cells(Rows.Count, 1).End(xlUp))
With cell
If .Offset(1, 0).Value < .Value Then
Range(firstCell, .Cells).Name = _
Format(.Value, "_000")
Set firstCell = .Offset(1, 0)
End If
End With
Next cell
End Sub


In article ,
"Robert" wrote:

I have a worksheet with rows of data. Col. A contains a
number. I sort the entire list by Col. A then I want to
create a named range for each change in Col. A.

For example, if Cells' A1, A2, and A3 all contain 999,
then I want to take all the Col. A cells with 999 and
create a named range of "999". Then, if Cells' A4, A5,
A6, and A7 all contain 888, then I want to take those 4
cells and create a named range of "888".

Any suggestions on the most efficent way to perform this
task?

Thanks in advance!

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Create named range

Names have to start with a letter and can not resemble a range reference.
Sub Tester1()
Dim Start As Range
Dim cell As Range
Dim vVal As Variant
Set Start = Range("A1")
vVal = Start.Value
For Each cell In Range(Cells(1, 1), _
Cells(1, 1).End(xlDown)(2))
If cell.Value < vVal Then
Range(Start, cell.Offset(-1, 0)) _
.Name = "Name_" & vVal
Set Start = cell
vVal = Start.Value
End If
Next

End Sub


--
Regards,
Tom Ogilvy




Robert wrote in message
...
I have a worksheet with rows of data. Col. A contains a
number. I sort the entire list by Col. A then I want to
create a named range for each change in Col. A.

For example, if Cells' A1, A2, and A3 all contain 999,
then I want to take all the Col. A cells with 999 and
create a named range of "999". Then, if Cells' A4, A5,
A6, and A7 all contain 888, then I want to take those 4
cells and create a named range of "888".

Any suggestions on the most efficent way to perform this
task?

Thanks in advance!



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
How to create a dynamic named range? Sunita Excel Discussion (Misc queries) 3 March 28th 08 07:47 PM
#value! error trying to create a simple dynamic named range Janis Excel Discussion (Misc queries) 1 August 3rd 07 07:20 PM
how do i create a named range excluding particular cells RobG2007 Excel Discussion (Misc queries) 4 July 25th 07 04:22 PM
inserting a named range into new cells based on a named cell Peter S. Excel Discussion (Misc queries) 1 June 4th 06 03:53 AM
Using a formula to create named range reference [email protected] Excel Worksheet Functions 4 June 29th 05 08:03 PM


All times are GMT +1. The time now is 04:24 PM.

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"