Thread: For each
View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Bernard Liengme[_2_] Bernard Liengme[_2_] is offline
external usenet poster
 
Posts: 563
Default For each

Not sure how you get 84 elements in C3:P84
However, here is an alternative way to cycle thru all the elements (left to
right, row by row) if you do not want to use Each and a counter
Sub tryme()
Set oRng = Range("C3:P84")
For j = 1 To oRng.Count
If j = 32 then MsgBox oRng(j)
Next j
End Sub

best wishes

"JMay" wrote in message
...
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