Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Help with Loop

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   Report Post  
Posted to microsoft.public.excel.programming
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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Help with Loop

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Help with Loop

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Help with Loop

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Help with Loop

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Help with Loop

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find loop doesn't loop JSnow Excel Discussion (Misc queries) 2 June 24th 09 08:28 PM
Advancing outer Loop Based on criteria of inner loop ExcelMonkey Excel Programming 1 August 15th 05 05:23 PM
Loop Function unable to loop Junior728 Excel Programming 1 July 28th 05 10:23 AM
Problem adding charts using Do-Loop Until loop Chris Bromley[_2_] Excel Programming 2 May 23rd 05 01:31 PM
HELP!!!! Can't stop a loop (NOT an infinite loop) TBA[_2_] Excel Programming 3 December 14th 03 03:33 PM


All times are GMT +1. The time now is 08:44 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"