Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default Multiple For/Next Loop help

Hello. Can somebody suggest a revised version of the following code
please: -

For I = 6 To ilastcolumn Step 42
For j = 7 To ilastcolumn Step 42
For k = 9 To ilastcolumn Step 42
For l = 35 To ilastcolumn Step 42
For m = 37 To ilastcolumn Step 42
For n = 38 To ilastcolumn Step 42
For o = 40 To ilastcolumn Step 42
For p = 41 To ilastcolumn Step 42
For q = 42 To ilastcolumn Step 42

textstring = (Cells(ActiveCell.Row, I).Value) & " " &
(Cells(ActiveCell.Row, j).Value) _
& " " & (Cells(ActiveCell.Row, k).Value) & " " & (Cells(ActiveCell.Row,
l).Value) _
& " " & (Cells(ActiveCell.Row, m).Value) & " " & (Cells(ActiveCell.Row,
n).Value) _
& " " & (Cells(ActiveCell.Row, o).Value) & " " & (Cells(ActiveCell.Row,
p).Value) _
& " " & (Cells(ActiveCell.Row, q).Value) & Chr(10)


Next q
Next p
Next o
Next n
Next m
Next l
Next k
Next j
Next I

I need every variable from i-q incrememented by it's next value each
time the (textstring = .. ) statement is encountered. I tried to
achieve that with the above code but i think i've coded it wrong, i
think instead of that what is actually happening is each variable is
going through it's increment cycle independently of the other over
variables before moving on to the next variable, which is running it's
own incremement cycle.

Any ideas how I get all the variables to incremement to there next
value at the same time?

thanks,

Gary.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 82
Default Multiple For/Next Loop help

Try this (it's sort of cumbersome, but should work)

j = 7
k = 9
l = 35
m = 37
n = 38
o = 40
p = 41
q = 42

For I = 6 To ilastcolumn Step 42

textstring = (Cells(ActiveCell.Row, I).Value) & " " &
(Cells(ActiveCell.Row, j).Value) _
& " " & (Cells(ActiveCell.Row, k).Value) & " " & (Cells(ActiveCell.Row,
l).Value) _
& " " & (Cells(ActiveCell.Row, m).Value) & " " & (Cells(ActiveCell.Row,
n).Value) _
& " " & (Cells(ActiveCell.Row, o).Value) & " " & (Cells(ActiveCell.Row,
p).Value) _
& " " & (Cells(ActiveCell.Row, q).Value) & Chr(10)

if j+42 = ilastcolumn then
j= ilastcolumn
else
j=J+42
end if

if k+42 = ilastcolumn then
k= ilastcolumn
else
k=k+42
end if

if l+42 = ilastcolumn then
l= ilastcolumn
else
l=l+42
end if

if m+42 = ilastcolumn then
m= ilastcolumn
else
m=m+42
end if

if n+42 = ilastcolumn then
n= ilastcolumn
else
n=n+42
end if

if o+42 = ilastcolumn then
o= ilastcolumn
else
o=o+42
end if

if p+42 = ilastcolumn then
p= ilastcolumn
else
p=p+42
end if

if q+42 = ilastcolumn then
q= ilastcolumn
else
q=q+42
end if

Next I


--
HTH

JonR


" wrote:

Hello. Can somebody suggest a revised version of the following code
please: -

For I = 6 To ilastcolumn Step 42
For j = 7 To ilastcolumn Step 42
For k = 9 To ilastcolumn Step 42
For l = 35 To ilastcolumn Step 42
For m = 37 To ilastcolumn Step 42
For n = 38 To ilastcolumn Step 42
For o = 40 To ilastcolumn Step 42
For p = 41 To ilastcolumn Step 42
For q = 42 To ilastcolumn Step 42

textstring = (Cells(ActiveCell.Row, I).Value) & " " &
(Cells(ActiveCell.Row, j).Value) _
& " " & (Cells(ActiveCell.Row, k).Value) & " " & (Cells(ActiveCell.Row,
l).Value) _
& " " & (Cells(ActiveCell.Row, m).Value) & " " & (Cells(ActiveCell.Row,
n).Value) _
& " " & (Cells(ActiveCell.Row, o).Value) & " " & (Cells(ActiveCell.Row,
p).Value) _
& " " & (Cells(ActiveCell.Row, q).Value) & Chr(10)


Next q
Next p
Next o
Next n
Next m
Next l
Next k
Next j
Next I

I need every variable from i-q incrememented by it's next value each
time the (textstring = .. ) statement is encountered. I tried to
achieve that with the above code but i think i've coded it wrong, i
think instead of that what is actually happening is each variable is
going through it's increment cycle independently of the other over
variables before moving on to the next variable, which is running it's
own incremement cycle.

Any ideas how I get all the variables to incremement to there next
value at the same time?

thanks,

Gary.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default Multiple For/Next Loop help

You are a genius, a gentleman and a scholar.

You do not know how much trouble you have saved me.

I can not express my gratitude!

Thanks.

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
How can I loop through a the values in multiple rows EMarre Excel Discussion (Misc queries) 6 May 13th 10 01:50 PM
Setting Multiple Variables with a loop jlclyde Excel Discussion (Misc queries) 6 November 11th 09 09:40 PM
Code to loop through multiple checkboxes ram Excel Programming 8 July 11th 06 04:03 PM
Summing loop for multiple worksheets Brian Easton Excel Programming 1 September 25th 04 12:43 AM
multiple cells in a loop jmorgs[_3_] Excel Programming 1 August 30th 04 04:24 PM


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