Consulting

Results 1 to 4 of 4

Thread: Solved: Manipulation on Array elements

  1. #1

    Solved: Manipulation on Array elements

    Dear all, I have an array of strings, like:

    [VBA]
    dim StringArray(5) as string
    StringArray(1) = "a"
    StringArray(2) = "b"
    StringArray(3) = "c"
    StringArray(4) = "d"
    StringArray(5) = "e"
    [/VBA]

    here the array length (in present case, which is '5') is basically a variable. Now what I want is to add all the array elements and put them as: "a, b, c, d, e".

    Is there any direct way to achieve that?

    Thanks and regards,

  2. #2
    [vba]sn=split("a|b|c|d|e","|")[/vba]

    or

    [VBA]sn = [index(char(96 +row(1:5)),)][/VBA]

    or

    [VBA]
    sn = [transpose(char(96 +row(1:5)))]

    [/VBA]

  3. #3
    VBAX Contributor GarysStudent's Avatar
    Joined
    Aug 2012
    Location
    Lakehurst, NJ, USA
    Posts
    127
    Location
    Use Join:

    [VBA]Sub luxation()
    Dim StringArray(1 To 5) As String
    Dim st As String
    StringArray(1) = "a"
    StringArray(2) = "b"
    StringArray(3) = "c"
    StringArray(4) = "d"
    StringArray(5) = "e"
    st = Join(StringArray, ", ")
    MsgBox st
    End Sub
    [/VBA]
    Have a Great Day!

  4. #4
    Thanks snb and GarysStudent for your help. GarysStudent's suggestion really served my purpose. Also thanking snb for looking into my problem.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •