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

948 Steps to 6 Figures by Learning Excel-VBA and Other Skills



Step 486 - 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


   Table of Contents | Send us your feedback | © 2025 All Rights Reserved | Edit