Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
For Each Next Loop
What does this return ?
j = Cells(Rows.Count, 4).End(xlUp)(2).Row MsgBox j Set rng1 = Range(Cells(2, 4), Cells(j, 4)) MsgBox rng1.Address Best wishes Harald "benb" skrev i melding ... I am using the following code: j = Cells(Rows.Count, 4).End(xlUp)(2).Row Set rng1 = Range(Cells(2, 4), Cells(j, 4) For Each cll In rng1 If Not cll.Value Like "NY*" Then cll.EntireRow.Clear End If Next cll When executed, this clears the contents of row 1 even though the range I want to work with is row 2 and down. I could use a different loop to accomplish the same thing, but I am really interested in understanding why the code is executing on elements outside of the specified group. Am I using it incorrectly or do I just not understand how this code works? Thanks. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
For Each Next Loop
Cool. Thanks for the feedback.
Best wishes Harald "benb" skrev i melding ... Thanks Harald. That helped me figure out the source of my problem. The range was shifting because some rows were deleted after I set the range. I just set the range later in the code and it works fine. Thanks again. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Find loop doesn't loop | Excel Discussion (Misc queries) | |||
Loop ? | Excel Discussion (Misc queries) | |||
help with a loop | Excel Discussion (Misc queries) | |||
Worksheet_Change - loop within a loop | Excel Programming | |||
HELP!!!! Can't stop a loop (NOT an infinite loop) | Excel Programming |