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

hi,

I am looking for a formula that would give me a for loop. you can also
give me a code in VB too..

This is what I am looking for in the for loop.

i=0, j=0, k=0
i=0, j=0, k=1
i=0, j=0, k=2
i=0, j=0, k=3

i=0, j=1, k=0
i=0, j=1, k=1
i=0, j=1, k=2
i=0, j=1, k=3

and so on.....

any ideas?

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

What is i ? Is that always 0...Also you have not mentioned the condition to
end the loop. Try the below and view the result in immediate window..


Sub Macro_Increment()

Dim i, j, k
i = 0: j = 0: k = 0

Do
If k = 4 Then j = j + 1: k = 0
Debug.Print i & "," & j & "," & k
k = k + 1
Loop Until j = 10

End Sub


If this post helps click Yes
---------------
Jacob Skaria


"Harish" wrote:

hi,

I am looking for a formula that would give me a for loop. you can also
give me a code in VB too..

This is what I am looking for in the for loop.

i=0, j=0, k=0
i=0, j=0, k=1
i=0, j=0, k=2
i=0, j=0, k=3

i=0, j=1, k=0
i=0, j=1, k=1
i=0, j=1, k=2
i=0, j=1, k=3

and so on.....

any ideas?


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

In a C program, I would always write my for loop like this:

for (i=0; i<=3; i++)
{
for (j=0; j<=3; j++)
{
for (k=0l k<=3; k++)
{
printf ("i = %d, j= %d, k=%d\n", i, j, k)
}
}
}
this code will give the result that i mentioned before in my post. In
VB i m not sure how that's done but i want the code to input the value
into the cell automatically. any ideas?





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default For loop

Option Explicit
Sub testme()

Dim i as long
dim j as long
dim k as long

for i = 0 to 3
for j = 0 to 3
for k = 0 to 3
msgbox i & " " & j & " " & k
next k
next j
next i

End sub

But I'm not sure what cells you want to populate.


Harish wrote:

In a C program, I would always write my for loop like this:

for (i=0; i<=3; i++)
{
for (j=0; j<=3; j++)
{
for (k=0l k<=3; k++)
{
printf ("i = %d, j= %d, k=%d\n", i, j, k)
}
}
}
this code will give the result that i mentioned before in my post. In
VB i m not sure how that's done but i want the code to input the value
into the cell automatically. any ideas?


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default For loop

I want the code to enter these values in the excel cells columns, A, B
and C. How do i do that?


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

i want the code to enter the values of i, j, and k into the excel
spreadsheet columns A, B and C automatically
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default For loop

What is the line to store values in a cell?
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default For loop

Sub LoopTest()

Dim lngRow, lngA, lngB, lngC As Long
lngRow = 1
For lngA = 0 To 3
For lngB = 0 To 3
For lngC = 0 To 3
ActiveSheet.Range("A" & lngRow) = lngA
ActiveSheet.Range("B" & lngRow) = lngB
ActiveSheet.Range("C" & lngRow) = lngC
lngRow = lngRow + 1
Next
Next
Next

End Sub



If this post helps click Yes
---------------
Jacob Skaria


"Harish" wrote:

In a C program, I would always write my for loop like this:

for (i=0; i<=3; i++)
{
for (j=0; j<=3; j++)
{
for (k=0l k<=3; k++)
{
printf ("i = %d, j= %d, k=%d\n", i, j, k)
}
}
}
this code will give the result that i mentioned before in my post. In
VB i m not sure how that's done but i want the code to input the value
into the cell automatically. any ideas?






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

Thanks a lot Jacob.
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default For loop

I have another problem and i think a nested for loop is applicable on
this problem

I have the following data:

x1 x3 x2
26.563 24.644 1.72
26.826 24.888 1.72
27.089 25.132 1.72
27.352 25.376 1.72
27.615 25.62 1.72
27.878 25.864 1.72
28.141 26.108 1.72
28.404 26.352 1.72
28.667 26.596 1.72
28.93 26.84 1.72
29.193 27.084 1.72
29.456 27.328 1.72
29.719 27.572 1.72
29.982 27.816 1.72
30.245 28.06 1.72
30.508 28.304 1.72
30.771 28.548 1.72
31.034 28.792 1.72
31.297 29.036 1.72
31.56 29.28 1.72

I have an equation that uses these 3 values. For example, x1 will be
held constant, while x3 changes for every iteration and then x1 will
change and after x3 will keep changing for every iteration....this is
similar to that for loop we just developed except i don;t know how to
read the values off the excel spreadsheet using VB since i m new to
VB. Appreciate your help. Thanks


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

How do i iterate the cells in for loop?
  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default For loop

how do i iterate the cells in the for loop?
  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default For loop

How do I iterate the cells?


On Apr 29, 2:00*am, Harish wrote:
I have another problem and i think a nested for loop is applicable on
this problem

I have the following data:

x1 * * *x3 * * *x2
26.563 *24.644 *1.72
26.826 *24.888 *1.72
27.089 *25.132 *1.72
27.352 *25.376 *1.72
27.615 *25.62 * 1.72
27.878 *25.864 *1.72
28.141 *26.108 *1.72
28.404 *26.352 *1.72
28.667 *26.596 *1.72
28.93 * 26.84 * 1.72
29.193 *27.084 *1.72
29.456 *27.328 *1.72
29.719 *27.572 *1.72
29.982 *27.816 *1.72
30.245 *28.06 * 1.72
30.508 *28.304 *1.72
30.771 *28.548 *1.72
31.034 *28.792 *1.72
31.297 *29.036 *1.72
31.56 * 29.28 * 1.72

I have an equation that uses these 3 values. For example, x1 will be
held constant, while x3 changes for every iteration and then x1 will
change and after x3 will keep changing for every iteration....this is
similar to that for loop we just developed except i don;t know how to
read the values off the excel spreadsheet using VB since i m new to
VB. Appreciate your help. Thanks


  #14   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default For loop

I thought Jacob's suggestion showed you how to do that.

Harish wrote:

What is the line to store values in a cell?


--

Dave Peterson
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
returning back to loop check condition without completing the loop ashish128 Excel Programming 13 April 3rd 08 12:53 PM
Loop to Filter, Name Sheets. If Blank, Exit Loop ryguy7272 Excel Programming 3 February 5th 08 03:41 PM
(Complex) Loop within loop to create worksheets klysell Excel Programming 1 March 20th 07 12:03 AM
Advancing outer Loop Based on criteria of inner loop ExcelMonkey Excel Programming 1 August 15th 05 05:23 PM
Problem adding charts using Do-Loop Until loop Chris Bromley[_2_] Excel Programming 2 May 23rd 05 01:31 PM


All times are GMT +1. The time now is 08:14 AM.

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"