Thursday, 21 May 2015

How to Join an Array of Strings into a single String in VBA

VBA Join Function
The VBA 'Join' Function joins the Substrings contained in an array, and returns a String by Concatenating the  Substrings separated by a specified delimiter.

Syntax :
StringName = join(Array Input, Delimiter)

Here , Array Input is the array that you want to place into a string.

Delimiter is an optional parameter that indicates what you want to place between elements are added to the string. By default this parameter is set to "".

Sub Split_Store_In_Array()

Dim MyStr(6) As String

'Array Input as follows
MyStr(0) = "This"
MyStr(1) = "Is"
MyStr(2) = "What"
MyStr(3) = "I"
MyStr(4) = "Want"
MyStr(5) = "To"
MyStr(6) = "Store"


'Concatenating/Joining all Arrary Values so as to form a single String
Conc_Str = Join(MyStr, "_")

MsgBox Conc_Str

End Sub

No comments:

Post a Comment

Follow Me by Email

ExcelKingdom-Popular Posts

ExcelKingdom-Random Posts