View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Frank[_8_] Frank[_8_] is offline
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