Learn How to use VBA uBound in Excel

Ok. Lets assume we have a variable called MyVariableTest which is of the data type string.

below is the code...

--------------
'Code starts below

Sub uBoundVBA()

'Here is how we define this variable
Dim MyVariable1 As String

' Now get a value assigned to the varible
MyVariableTest = "My Variable Test"

' Now lets split this text using the delimiter " " - space
' this split action will help me separate the three text
' elements i.e. My, Variable, Test

'we would need to put the splitted value in a new variable

MySplittedArrray = Split(MyVariableTest, " ")

' Now MySplittedArrray has the three text elements stored in an
' arrary which is MySplittedArrray

' You would use uBound VBA property to get the last text element
' And you would use lBound VBA property to get the first one
' so if you want "Test" as your output use uBound if you want
' "My" as your output use lBound
' uBound will give you the number of elements the main string was broken into after the split. Note that array counting start with 0 so in this case uBound will return you 2

' Now simply return it

MsgBox UBound(MySplittedArrray)
' this will output 2

' if you want to use UBound to Print Test
' use the statement below...

MsgBox MySplittedArrray(UBound(MySplittedArrray))
' this will output Test

End Sub

'Code ends here
-------------------------------------

If you like this post do let me know and feel free to comment.