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. Subscribe to our Windows Secrets Newsletter - It's Free!

    Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    5,870
    Thanks
    0
    Thanked 79 Times in 75 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.

  4. #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)

  5. #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
  •