Results 1 to 3 of 3
  1. #1
    5 Star Lounger
    Join Date
    Mar 2001
    Posts
    989
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    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).

  3. #3
    5 Star Lounger
    Join Date
    Mar 2001
    Posts
    989
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by HansV View Post
    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.

Posting Permissions

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