Announcement

Collapse
No announcement yet.

Parse Delimited String to Rows in VBA

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Parse Delimited String to Rows in VBA

    Hi there,

    I'm sure there's an answer to this that I simply don't know the search terms to discover, so my apologies in advance if it's a dumb question.

    I currently have a function which grabs a csv file from a variable URL, saves it to a temporary directory and then imports it neatly and delimited into a new sheet. If possible though, I'd love to just do the whole process in VBA and skip the saving and opening steps.

    I have got as far as xmlhttp-ing the csv into a string, which is working perfectly. My dilemma now is that I haven't the foggiest idea how to parse that string (delimited by spaces) into rows. The closest I've come to an answer is automating Text to Columns on my string and then transposing the resulting columns to rows, but that just seems clunky, and I'm wondering if there's a more elegant method I can deploy.

    Strings that will be passed to this function are never more than 365 entries long, but can be any value less than that.

    Any pointers, solutions or general guidance would be much much appreciated!

  • #2
    Re: Parse Delimited String to Rows in VBA

    Explore Split() function and arrays
    Cheers,

    S M C

    Click To Read: How To Use Tags In Your Threads/Posts
    Please take time to read Forum Rules before posting
    Message To Cross Posters

    Comment


    • #3
      Re: Parse Delimited String to Rows in VBA

      thanks for the heads up - I need to learn how to use arrays, of which I remain shamefully ignorant.

      One question on that front - I'm assuming that given the variable number of entries per string, I'll be working with dynamic arrays. Do I need ultimately to ReDim this to a particular number of entries (ie 1 to 365) or can it remain unspecified?

      Comment


      • #4
        Re: Parse Delimited String to Rows in VBA

        No you shouldn't be doing a ReDim there. The array would expand based on how many elements are passed by the Split function.
        Cheers,

        S M C

        Click To Read: How To Use Tags In Your Threads/Posts
        Please take time to read Forum Rules before posting
        Message To Cross Posters

        Comment


        • #5
          Re: Parse Delimited String to Rows in VBA

          fantastic - I shall get to work.

          Thank you for the incredibly swift response

          Comment


          • #6
            Re: Parse Delimited String to Rows in VBA

            example:
            cells(1,1).resize(ubound(split("textstring",vbcrLf))+1)=worksheetfunction.transpose(split("textstring",vbcrLf))
            columns(1).TexttoColumns , ......

            Comment

            Working...
            X