By using expertatexcel.com you agree to our cookie policy, We and our partners operate globally and use cookies, for multiple purposes

Become an Σxpert at Σxcel.com

 


For loop - lbound ubound

The for-loop is very useful for processing data in arrays.


Sub for_loop_demo()

s = "blue,green,red,orange,yellow"

a = split(s,",")

for i = lbound(a) to ubound(a)
    debug.print a(i)
next

End Sub


LBound(array)

The LBound function returns the lower index of an array which will usually be 0.

The UBound function returns the upper index of an array which will be the number of items in the array minus 1.

To determine the number of items add 1 to the UBound of the array

nbr_of_items = UBound(array) + 1

You