Microsoft Office Tutorials and References
In Depth Information
Controlling Execution
[Exit Do]
Loop [Until condition]
The following example demonstrates the first syntax of the Do Until loop. This example makes
the code a bit clearer because it avoids the negative comparison required in the Do While
Function RowOfLargest4(c)
NumRows = Rows.Count
MaxVal = Application.Max(Columns(c))
r = 1
Do Until Cells(r, c) = MaxVal
r = r + 1
RowOfLargest4 = r
End Function
Finally, the following function is the same procedure but is rewritten to use the second syntax of
the Do Until loop:
Function RowOfLargest5(c)
NumRows = Rows.Count
MaxVal = Application.Max(Columns(c))
r = 0
r = r + 1
Loop Until Cells(r, c) = MaxVal
RowOfLargest5 = r
End Function
The On Error statement
Undoubtedly, you’ve used one of Excel’s worksheet functions in a formula and discovered that
the formula returns an error value (for example, #VALUE!). A formula can return an error value in
a number of situations, including these:
h You omitted one or more required argument(s).
h An argument was not the correct data type (for example, text instead of a value).
h An argument is outside of a valid numeric range (division by zero, for example).
Search JabSto ::

Custom Search