Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Redefining a Named Range In A Loop

I want to loop through a range of cells and test for a condition. When the
first cell that meets the condition is found, add a defined name (i.e.
MyRange). As I continue looping through the cells, each cell that meets the
condition has to be added to that defined name.

Is there an easier way to do this rather than manipulate the RefersTo string?

Frank

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,337
Default Redefining a Named Range In A Loop

will this work?

Sub setupname()
With Range("a1:a" & Cells(Rows.Count, 1).End(xlUp).Row)
Set c = .Find(2, LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
mystring = mystring & "," & c.Address
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < firstAddress
End If
'MsgBox Right(mystring, Len(mystring) - 1)
ActiveWorkbook.Names.Add Name:="newname", RefersTo:= _
"=" & Right(mystring, Len(mystring) - 1)
End With
End Sub

--
Don Guillett
SalesAid Software

"Frank" wrote in message
...
I want to loop through a range of cells and test for a condition. When the
first cell that meets the condition is found, add a defined name (i.e.
MyRange). As I continue looping through the cells, each cell that meets

the
condition has to be added to that defined name.

Is there an easier way to do this rather than manipulate the RefersTo

string?

Frank



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Redefining a Named Range In A Loop

Hi Frank,

Is there an easier way to do this rather than manipulate
the RefersTo string?


Try, perhaps, something like:
'==============
Public Sub ATester3()
Dim Rng As Range
Dim rCell As Range
Dim Rng2 As Range
Dim WB As Workbook
Dim SH As Worksheet

Set WB = ActiveWorkbook '<<====== CHANGE
Set SH = WB.Sheets("Sheet1") '<<====== CHANGE
Set Rng = SH.Range("A1:D20") '<<====== CHANGE

For Each rCell In Rng.Cells
If rCell.Value 10 Then '<<====== CHANGE
If Rng2 Is Nothing Then
Set Rng2 = rCell
Else
Set Rng2 = Union(rCell, Rng2)
End If
End If
Next rCell

If Not Rng2 Is Nothing Then
Rng2.Name = "Test2"
End If

End Sub
'<<==============

---
Regards,
Norman



"Frank" wrote in message
...
I want to loop through a range of cells and test for a condition. When the
first cell that meets the condition is found, add a defined name (i.e.
MyRange). As I continue looping through the cells, each cell that meets
the
condition has to be added to that defined name.

Is there an easier way to do this rather than manipulate the RefersTo
string?

Frank



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Redefining a Named Range In A Loop

Perfect Norman !

That's exactly what I was looking for.

Frank

"Norman Jones" wrote:

Hi Frank,

Is there an easier way to do this rather than manipulate
the RefersTo string?


Try, perhaps, something like:
'==============
Public Sub ATester3()
Dim Rng As Range
Dim rCell As Range
Dim Rng2 As Range
Dim WB As Workbook
Dim SH As Worksheet

Set WB = ActiveWorkbook '<<====== CHANGE
Set SH = WB.Sheets("Sheet1") '<<====== CHANGE
Set Rng = SH.Range("A1:D20") '<<====== CHANGE

For Each rCell In Rng.Cells
If rCell.Value 10 Then '<<====== CHANGE
If Rng2 Is Nothing Then
Set Rng2 = rCell
Else
Set Rng2 = Union(rCell, Rng2)
End If
End If
Next rCell

If Not Rng2 Is Nothing Then
Rng2.Name = "Test2"
End If

End Sub
'<<==============

---
Regards,
Norman



"Frank" wrote in message
...
I want to loop through a range of cells and test for a condition. When the
first cell that meets the condition is found, add a defined name (i.e.
MyRange). As I continue looping through the cells, each cell that meets
the
condition has to be added to that defined name.

Is there an easier way to do this rather than manipulate the RefersTo
string?

Frank




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
If any cell in named range = 8 then shade named range JJ[_8_] Excel Programming 3 August 26th 05 11:09 PM
Loop thru named range of second sheet Bill Sturdevant[_2_] Excel Programming 3 July 29th 05 07:15 PM
plz help: creating named range in VBA, loop goes haywire KR Excel Programming 2 April 14th 05 07:25 PM
Redefining a new Range area - Thanks Nick Hodge and Norman Paul Silverman Excel Programming 0 September 14th 04 11:45 AM
Redefining a new Range area Paul Silverman Excel Programming 2 September 12th 04 12:02 PM


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