Thread: For each
View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein Rick Rothstein is offline
external usenet poster
 
Posts: 5,934
Default For each

Can you make use of something like this...

Set MyRange = Range("C3:P8")
OffsetIntoRange = 32
DesiredCellAddress = MyRange(OffsetIntoRange).Address
For Each C In MyRange
.....
.....
If C.Address = DesiredCellAddress Then
' You found the cell, so do whatever you want with it
End If
......
Next

--
Rick (MVP - Excel)



"JMay" wrote in message
...
Thanks John,,

Sorry I wasn't clear in stating the facts. My oRng (C3:P8) contains a
unique set of integers. In my For Each loop a Variable interger is
supplied,
say 32. I need for my activecell to change to the cell address that is
oRng(32).

Jim

"john" wrote:

see if this helps you

Sub aaa()
Dim c As Range
Dim oRng As Range

'code

Set oRng = Range("C3:P84")

For Each c In oRng

If c.Value = 32 Then MsgBox c.Address

Next c

End Sub
--
jb


"JMay" wrote:

I've assigned a Obj variable: Set oRng=C3:P84 (there are 84
elements/items)
So I then have

Dim c as Range
'code
For each c in oRng

Next c

As I step thru the code I need to perform an action when (using IF)
c reaches element, say 32 -- How is this done using the For each
method?
I know I could assign a counter i (and do the i = i + 1 inside), but is
that
necessary using the For each.

Thanks in advance..

Jim