Microsoft Office Tutorials and References
In Depth Information
NumRows = Rows.Count
MaxVal = Application.Max(Columns(c))
r = 1
Do While Cells(r, c) <> MaxVal
r = r + 1
Loop
ROWOFLARGEST2 = r
End Function
The variable r starts out with a value of 1 and increments within the Do While loop. The looping continues as
long as the cell being evaluated is not equal to MaxVal. When the cell is equal to MaxVal, the loop ends, and the
function is assigned the value of r. Notice that if the maximum value is in row 1, the looping does not occur.
The following procedure uses the second Do While loop syntax. The loop always executes at least once.
Function ROWOFLARGEST(c)
MaxVal = Application.Max(Columns(c))
r = 0
Do
r = r + 1
Loop While Cells(r, c) <> MaxVal
ROWOFLARGEST = r
End Function
Do While loops can also contain one or more Exit Do statements. When an Exit Do statement is encountered,
the loop ends immediately.
Do Until loops
The Do Until loop structure closely resembles the Do While structure. The difference is evident only when the
condition is tested. In a Do While loop, the loop executes while the condition is true. In a Do Until loop, the
loop executes until the condition is true. Do Until also has two syntaxes:
Do [Until condition]
[instructions]
[Exit Do]
[instructions]
Loop
or
Do
[instructions]
[Exit Do]
[instructions]
Loop [Until condition]
Search JabSto ::




Custom Search