Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Joe,
Try: Public Sub Tester001() Dim cell As Range, rng As Range Dim LRow As Long LRow = Cells(Rows.Count, "E").End(xlUp).Row With Sheets("Scroller Info") Set rng = .Range("E2:e" & LRow) End With For Each cell In rng With cell If .Value < .Offset(-1).Value Then CreatePSPortLabel End If End With Next End Sub '<<============= --- Regards, Norman "Joe Fish" wrote in message oups.com... 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 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Norman,
This does the same thing as mine. And by the way, there are no blank cells in the range- and there wouldn't ever be. It's so strange, because the loop just seems to stop for no reason. |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Joe,
It's so strange, because the loop just seems to stop for no reason. What do you mean by stop? When I tested the code, I added the line: Debug.print cell.Address and was thus able to verify that the code processed all the requisite cells. --- Regards, Norman "Joe Fish" wrote in message ups.com... Norman, This does the same thing as mine. And by the way, there are no blank cells in the range- and there wouldn't ever be. It's so strange, because the loop just seems to stop for no reason. |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
When I say it stops, I mean it runs the internal macro for every cell
from Row 2 to Row 28, then it stops, meaning the active cell stops advancing and the macro doesn't run from Row 29 through 88 (the end of the column). |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Joe,
The code, as written, makes no provision for selections and, consequently, the active cell should not change when the code is run. Are any of the E29:E88 cells populated? --- Regards, Norman "Joe Fish" wrote in message oups.com... When I say it stops, I mean it runs the internal macro for every cell from Row 2 to Row 28, then it stops, meaning the active cell stops advancing and the macro doesn't run from Row 29 through 88 (the end of the column). |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Find loop doesn't loop | Excel Discussion (Misc queries) | |||
Advancing outer Loop Based on criteria of inner loop | Excel Programming | |||
Loop Function unable to loop | Excel Programming | |||
Problem adding charts using Do-Loop Until loop | Excel Programming | |||
HELP!!!! Can't stop a loop (NOT an infinite loop) | Excel Programming |