Dim statement is used to declare array and string type variable. Here not defining the array size. VBA Split function creates an array to store an array elements. We use comma delimiter to split string.
Table of Contents:
Macro Code for VBA Split String into Array in Excel
Let us see the example macro code for VBA Split String and store elements in Excel. These elements are stored in an array.
'VBA Split String into Array in Excel Sub VBA_Split_String_into_Array() 'Variable Declaration Dim aString() As String Dim sInputString As String, sDelimiter As String 'Input Value sInputString = "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday" 'Delimiter Value sDelimiter = "," 'Split string into array aString = Split(sInputString, sDelimiter) 'Displau Output Message MsgBox "Array First Value : " & aString(0) & vbCrLf & "Array Second Value : " & aString(1) & vbCrLf & _ "Array Third Value : " & aString(2) & vbCrLf & "Array Fourth Value : " & aString(3) & vbCrLf & _ "Array Fifth Value : " & aString(4) & vbCrLf & "Array Sixth Value : " & aString(5) & vbCrLf & _ "Array Seventh Value : " & aString(6), _ vbInformation, "VBAF1" End Sub
Here is the output screen shot of the above macro.
You can view array elements in watch window.
Hi there, I ⅼog on to ʏour blog daily. Your story-telling style is
witty, keep it up!