Results 1 to 4 of 4
  1. #1
    4 Star Lounger
    Join Date
    May 2004
    Location
    Toronto, Ontario, Canada
    Posts
    425
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Parse variable string (excel 2003)

    Hi all,

    I have a string variable that I would like to parse much the same as "texttocolumns" I would like to know if there is a way to achieve a parse without using a hidden sheet.?

    Thanks
    Darryl

  2. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    5,896
    Thanks
    0
    Thanked 86 Times in 82 Posts

    Re: Parse variable string (excel 2003)

    What kind of parse do you want to do? If it's delimited, you can use the split function - e.g.
    <pre>strWhatever = "test1,test2,test3"
    varData = split(strwhatever, ",")
    for n = lbound(vardata) to ubound(vardata)
    ..do whatever you want with the bits
    next n
    </pre>

    Regards,
    Rory
    Microsoft MVP - Excel.

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 Posts

    Re: Parse variable string (excel 2003)

    Check out the Split function in the VBA help. It will split a variable according to the delimiter that you specify. The result is an array. Here is an example:
    <code>
    Sub Test()
    Dim strVar As String
    Dim arrParts() As String
    Dim i As Integer
    strVar = "this/that/other/such"
    arrParts = Split(strVar, "/")
    For i = LBound(arrParts) To UBound(arrParts)
    Debug.Print i, arrParts(i)
    Next i
    End Sub
    </code>
    If you run this macro, the results will be displayed in the Immediate window (just as an illustration)

  4. #4
    4 Star Lounger
    Join Date
    May 2004
    Location
    Toronto, Ontario, Canada
    Posts
    425
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Re: Parse variable string (excel 2003)

    Thanks guys,

    both examples are great!

    Darryl.

Posting Permissions

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