Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Nested loop order?


Hey everyone, another bit of code here and I want to make sure this is
going to run in the order that I think it will. It consists of a
"nested" for loop. I would like it to run the outer one one time for
every 9 times the inner one runs. In other words I have one for loop
representing the column value and the inner for loop represented the
row value. I want it to perform the calculations for one column at a
time all the way down before it moves to the next. Here is the code:


Code:
--------------------

Public Function results() As Double

Dim answers(9, 9) As Double
Dim i, j, component As intger

For i = 20 To 29

For j = 7 To 15

ThisWorkbook.Worksheets("Calculations").Cells(i, j).Select
component = ThisWorkbook.Worksheets("Calculations").Cells(Acti veCell.row, 6).Value

Select Case component
Case 1

Case 2

Case Else

Next j

Next i

End Function

--------------------


Ignore the select case command I am not too concerned with that right
now, just the for loops.

Thanks.

~Jason


--
jclark419
------------------------------------------------------------------------
jclark419's Profile: http://www.excelforum.com/member.php...o&userid=25430
View this thread: http://www.excelforum.com/showthread...hreadid=391360

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Nested loop order?

For i = 20 To 29
For j = 7 To 15
ThisWorkbook.Worksheets("Calculations").Cells(i, j).Select
Next j
Next i

as written, this works row by row across all columns (change a row, work on
columns 7 to 15)

perhaps you meant
.Cells(j,i).Select

otherwise you would reverse the loops

For j= 7 To 15
For i= 20 To 29
ThisWorkbook.Worksheets("Calculations").Cells(i, j).Select
Next i
Next j

--
Regards,
Tom Ogilvy


"jclark419" wrote
in message ...

Hey everyone, another bit of code here and I want to make sure this is
going to run in the order that I think it will. It consists of a
"nested" for loop. I would like it to run the outer one one time for
every 9 times the inner one runs. In other words I have one for loop
representing the column value and the inner for loop represented the
row value. I want it to perform the calculations for one column at a
time all the way down before it moves to the next. Here is the code:


Code:
--------------------

Public Function results() As Double

Dim answers(9, 9) As Double
Dim i, j, component As intger

For i = 20 To 29

For j = 7 To 15

ThisWorkbook.Worksheets("Calculations").Cells(i, j).Select
component =

ThisWorkbook.Worksheets("Calculations").Cells(Acti veCell.row, 6).Value

Select Case component
Case 1

Case 2

Case Else

Next j

Next i

End Function

--------------------


Ignore the select case command I am not too concerned with that right
now, just the for loops.

Thanks.

~Jason


--
jclark419
------------------------------------------------------------------------
jclark419's Profile:

http://www.excelforum.com/member.php...o&userid=25430
View this thread: http://www.excelforum.com/showthread...hreadid=391360



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Nested loop order?

Jason,

The looping is fine: it is your other code that worries me: you don't do anything with the cell
after you select it except pick up the value from column F of its row, so why loop through the
columns?

HTH,
Bernie
MS Excel MVP


"jclark419" wrote in message
...

Hey everyone, another bit of code here and I want to make sure this is
going to run in the order that I think it will. It consists of a
"nested" for loop. I would like it to run the outer one one time for
every 9 times the inner one runs. In other words I have one for loop
representing the column value and the inner for loop represented the
row value. I want it to perform the calculations for one column at a
time all the way down before it moves to the next. Here is the code:


Code:
--------------------

Public Function results() As Double

Dim answers(9, 9) As Double
Dim i, j, component As intger

For i = 20 To 29

For j = 7 To 15

ThisWorkbook.Worksheets("Calculations").Cells(i, j).Select
component = ThisWorkbook.Worksheets("Calculations").Cells(Acti veCell.row, 6).Value

Select Case component
Case 1

Case 2

Case Else

Next j

Next i

End Function

--------------------


Ignore the select case command I am not too concerned with that right
now, just the for loops.

Thanks.

~Jason


--
jclark419
------------------------------------------------------------------------
jclark419's Profile: http://www.excelforum.com/member.php...o&userid=25430
View this thread: http://www.excelforum.com/showthread...hreadid=391360



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
Nested If Loop Limitation for Excel 2003 raj74 Excel Discussion (Misc queries) 9 March 1st 09 06:14 PM
Nested loop [email protected] Excel Worksheet Functions 1 April 5th 07 12:50 AM
Nested Loop Link ashcrusher Excel Worksheet Functions 0 January 13th 06 03:46 AM
Nested Loop Frank Kabel Excel Programming 6 September 12th 04 02:41 AM
Nested loop with ranking jp Excel Programming 2 October 2nd 03 03:28 PM


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