Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Reddit
Contact us
Hide Buttons

VBA-Excel: Array Functions – LBound and UBound()

Description:

 LBound and UBound() Func­tions returns the start­ing index ( Lower Bound) and End­ing index (Upper Bound) of an array.

Format:

LBound(arrAr­ray­Name [, dimension])

UBound(arrAr­ray­Name [, dimension])

 

Arguments:
  • arrAr­ray­Name
    • Manda­tory
    • Type: Array
    • Array whose lower or upper bound needs to found

Exam­ple:

Function FnLowerUpperBound()

    Dim arrOneDArray(1 To 5)

    Dim arrTwoDArray(1 To 5, -2 To 10)

    Dim arrMultiDArray(0 To 4, -2 To 4, 2 To 7)

  Dim strString

  strString = "LBound of arrOneDArray is: " & LBound(arrOneDArray) & vbCrLf

  strString = strString & "LBound of 2nd dimension of arrTwoDArray is: " & LBound(arrTwoDArray, 2) & vbCrLf

  strString = strString & "LBound of 3rd dimension of arrMultiDArray is: " & LBound(arrMultiDArray, 3) & vbCrLf

  MsgBox strString

  strString = "UBound of arrOneDArray is: " & UBound(arrOneDArray) & vbCrLf

  strString = strString & "UBound of 2nd dimension of arrTwoDArray is: " & UBound(arrTwoDArray, 2) & vbCrLf

  strString = strString & "UBound of 3rd dimension of arrMultiDArray is: " & UBound(arrMultiDArray, 3) & vbCrLf

  MsgBox strString

End Function
Array functions-LBound

Array functions-LBound

 

Array functions-UBound()

Array functions-UBound()

 

You may also like...

2 Responses

  1. I need help, about array()

    I have three columns in a spread­sheet (example):

    what I need is to break to a new line each time it encoun­ters the word “lot”, not­ing that there are prod­ucts that do not have lots as in the delta exam­ple item.

    before
    ID Descrip­tion obser­va­tions
    123 prod­uct alpha (Lot: 3911924, Qty: 70, Dt Val: 30/10 / 2016Lote: 3901749, Qty: 20, Dt Val: 30/10 / 2016Lote: 4201107, Qty: 410, Val Deuteron­omy: 30/07 / 2017Lote : 4249269, Qty: 4110, Dt Val: 30/08 / 2017Lote: 4258339, Qty: 390, Dt Val: 30/08/2017)

    after
    123 alpha prod­uct Lot: 3911924, Qty: 70, Dt Val: 10/30/2016
    123 alpha prod­uct Lot: 3901749, Qty: 20, Dt Val: 10/30/2016
    123 alpha prod­uct Lot: 4201107, Qty: 410, Dt Val: 07/30/2017
    123 alpha prod­uct Lot: 4249269, Qty: 4110, Dt Val: 30/08/2017
    123 alpha prod­uct Lot: 4258339, Qty: 390, Dt Val: 30/08/2017

    As I did not find solu­tion and con­sider a good exam­ple, I appre­ci­ate the help

    • SJ says:

      You said you have 3 columns in spread­sheet, in your exam­ple can you tell me whats value those 3 columns con­tains, it looks to me a one sin­gle string,
      It can be done shouldnt take much time once i know what is there in 3 columns separately.

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: