Creating dummy output data
We'll use the ACTUAL number of groups to output dummy output data of 2500 for each group. To do this we need a LOOP. We'll do the same thing two different ways to demonstrate two of the many different types of loops. The loop we will use are the loops I use most often.
In traditional programming there are three different coding structures:
a. Sequence. We've already used sequences, to perform tasks one after another.
b. Decision. The most common decision statement is the 'if' statement. We'll discuss 'If' statements in the future.
c. Loop. A loop is used to do a repetitive task more efficiently than multiple sequence statements.
For example if we have 4 groups of data. The following SEQUENCE code would output the data in rows 9 and 10 Columns A thru D. The sequence is VERY EASY to read. It is also very easy to make TYPING MISTAKES, because the sequence is usually created using 'cut and paste'. It is very easy to have the wrong 'Cell Adress' or the wrong 'Group Number'. You also have to know ahead of time that there are EXACTLY 4 groups.
The following example uses a 'For' loop. Enter 4 for the number of 'Groups in Cell 'B5'. See what happens if you enter 3 groups or 0 groups or -1 groups. The output will be the same as for the sequence above. The code is a MORE DIFFICULT to read than the code for a sequence. It is a lot more flexible, because you don't have to have EXACTLY 4 groups.
Items of interest above:
1. The '&' is used to concatenate strings. Even though 'i' is a number, Excel knows to treat it as a 'string' in this context. If the value of i is 3, then ' "Group " & i' will become 'Group 3'.
2. The Offset statement. The offset statement is of the form 'Offset(rows to offset, columns to offset)
3. For loops that count up by a number other than 1.
4. For loops that count DOWN.
Next time we'll do the same thing with a WHILE loop.
Lewis
Bookmarks