#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default For loop...

Hello,
I have a single worksheet, with an unknown number of rows/columns.
Essentially, I would like to go through each non-empty line and based on a
value in any one of the columns, perform some action, like this
(pseudocode):

For i = 2 to (max number of rows) //if Ax (x=column) is empty/null, there
are no more 'records'
{
if Ci = 1
copy entire row i to Worksheet 2
if Ci = 2
copy entire row i to Worksheet 3
if (Ci = 3 AND Di = 4)
copy entire row i to Worksheet 4
else
copy entire row i to Worksheet 5
}

I'm missing something simple, but can't figure out what the easiest way to
loop through all records.

Any help would be appreciated.
Regards, Alan


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,089
Default For loop...

Alan

this basic code will give you the loop framework you need:

Sub ProcessColumnC()
Dim LastRow As Long
Dim i As Long
LastRow = Range("C65536").End(xlUp).Row
For i = 1 To LastRow
'your code
MsgBox Range("C" & i)
Next
End Sub

Record the code for copying rows from one sheet to another and adjust as
necessary. If you've got a few options you're probably best using a Select
Case block on the cells (Range("C" & i))

Regards

Trevor


"Alan L. Wagoner" wrote in message
...
Hello,
I have a single worksheet, with an unknown number of rows/columns.
Essentially, I would like to go through each non-empty line and based on a
value in any one of the columns, perform some action, like this
(pseudocode):

For i = 2 to (max number of rows) //if Ax (x=column) is empty/null, there
are no more 'records'
{
if Ci = 1
copy entire row i to Worksheet 2
if Ci = 2
copy entire row i to Worksheet 3
if (Ci = 3 AND Di = 4)
copy entire row i to Worksheet 4
else
copy entire row i to Worksheet 5
}

I'm missing something simple, but can't figure out what the easiest way to
loop through all records.

Any help would be appreciated.
Regards, Alan




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
for each loop april Excel Discussion (Misc queries) 6 November 19th 09 09:36 PM
Find loop doesn't loop JSnow Excel Discussion (Misc queries) 2 June 24th 09 08:28 PM
while loop Arun Kumar Saha Excel Worksheet Functions 2 June 19th 07 01:31 PM
help with a loop BeJay Excel Discussion (Misc queries) 3 May 19th 06 12:24 PM
Loop help PaulW Excel Discussion (Misc queries) 0 May 8th 06 04:00 PM


All times are GMT +1. The time now is 06:48 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"