View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Don Guillett[_4_] Don Guillett[_4_] is offline
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