Thread: Help with Loop
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jim Thomlinson[_4_] Jim Thomlinson[_4_] is offline
external usenet poster
 
Posts: 1,119
Default Help with Loop

Do you have a blank cell in the range that you are trying to loop through.
xlDown will stop at the first blank cell which might be why you are having
the problem. Give this a whirl...

Dim cell As Range, rng As Range

With Sheets("Scroller Info")
Set rng = .Range(.Range("E2"), .Cells(rows.count, "E").end(xlUp))
End With

For Each cell In rng
If cell.Value < cell.Offset(-1, 0).Value Then
CreatePSPortLabel
End If
Next

--
HTH...

Jim Thomlinson


"Joe Fish" wrote:

Hi,
I've tried coming at this a few ways, but I can't seem to make this run
the way I want. Ideally, each cell in the range is compared to the cell
above it. If it's the same, nothing happens. If it's different, the
Macro CreatePSPortLabel executes (which works fine).

What happens now is it runs the macro for every cell, and stops halfway
through the range.

Any ideas are welcome.
Thanks,
Fish

Dim cell As Range, rng As Range

With Sheets("Scroller Info")
Set rng = .Range(.Range("E2"), .Range("E2").End(xlDown))
End With

For Each cell In rng
If cell.Value < cell.Offset(-1).Value Then
CreatePSPortLabel
End If
Next