Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default 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
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
Loop ? chrisnsmith Excel Discussion (Misc queries) 6 February 21st 09 03:54 PM
help with a loop BeJay Excel Discussion (Misc queries) 3 May 19th 06 12:24 PM
Worksheet_Change - loop within a loop bgm Excel Programming 1 January 19th 04 01:27 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 06:28 PM.

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

About Us

"It's about Microsoft Excel"