• Convert comma list to array

    Author
    Topic
    #463931

    Hello.
    In one cell I have a list of comma separated values: e.g. ‘1,2,7’. How can I push the separate values
    into a VBA array? Another example might be ‘1,22,34,40’ – so the number of items and their “width” will vary.

    Thanks, Andy.

    Viewing 0 reply threads
    Author
    Replies
    • #1185803

      Let’s say the list is in cell A1. Use the following code.

      Dim arr As Variant
      arr = Split(Range(“A1”), “,”)

      Note: by default, the array index will be zero-based, i.e. the first element is arr(0).
      The index of the last element is UBound(arr).

      • #1185812

        Let’s say the list is in cell A1. Use the following code.

        Dim arr As Variant
        arr = Split(Range(“A1”), “,”)

        Note: by default, the array index will be zero-based, i.e. the first element is arr(0).
        The index of the last element is UBound(arr).

        That’s great, thanks. I was trying to look at each character in turn to find the commas, but
        it was getting a bit messy. Andy.

    Viewing 0 reply threads
    Reply To: Convert comma list to array

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: