+ Reply to Thread
Results 1 to 6 of 6

Remove text between quotes, variable length and number of quotes

Hybrid View

  1. #1
    Forum Contributor JP Romano's Avatar
    Join Date
    10-09-2008
    Location
    Princeton, NJ
    MS-Off Ver
    2010
    Posts
    500

    Remove text between quotes, variable length and number of quotes

    Hi all... I'm attempting to clean up some rather ugly strings, and would like to automate a process to clear out all the data with the exception of what's between quotations.

    The strings are variable length, and could have anywhere from 0 to 6 sets of quotations.

    For example

    From this
    aliasid:6558 enabled:0 yk:2 aclass:1 ticker:"SHE US" aliastext:"SHENGKAI" strength:1003 chgid:1826630 usage:2
    I want to be left with
    SHE US SHENGKAI
    Because this will sit in the middle of a larger macro, I'd much prefer to do this with vba code than a formula, but if the formula is the way to go, I can work with it.

    Thank you so much for any help!
    Last edited by JP Romano; 10-14-2011 at 09:51 AM. Reason: Resolved

  2. #2
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Remove text between quotes, variable length and number of quotes

    How's this for you?

    Sub GetQuoted()
    
    Const sDELIMITER = " "
    
    Dim sTestString As String
    Dim avSplitText As Variant
    Dim lLoop As Long
    Dim sTmpString
    
    sTestString = "aliasid:6558 enabled:0 yk:2 aclass:1 ticker:" & Chr(34) & "SHE US" & Chr(34) & "aliastext:" & Chr(34) & "SHENGKAI" & Chr(34) & " strength:1003 chgid:1826630 usage:2"
    sTmpString = ""
    
    avSplitText = Split(sTestString, Chr(34))
    
    For lLoop = LBound(avSplitText) + 1 To UBound(avSplitText) Step 2
      sTmpString = sTmpString & avSplitText(lLoop) & sDELIMITER
    Next lLoop
    
    If Len(sTmpString) > 0 Then
      sTmpString = Left(sTmpString, Len(sTmpString) - Len(sDELIMITER))
    End If
    
    MsgBox sTmpString
    
    End Sub

  3. #3
    Forum Contributor JP Romano's Avatar
    Join Date
    10-09-2008
    Location
    Princeton, NJ
    MS-Off Ver
    2010
    Posts
    500

    Re: Remove text between quotes, variable length and number of quotes

    Made minor modifications and it worked like a charm. THANK YOU!

  4. #4
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Remove text between quotes, variable length and number of quotes

    Sub snb()
     c00 = "aliasid:6558 enabled:0 yk:2 aclass:1 ticker:""SHE US"" aliastext:""SHENGKAI"" strength:1003 chgid:1826630 usage:2"
     msgbox  Join(Filter(Split(Replace("~" & c00, Chr(34) & Space(1), Chr(34) & "~"), Chr(34)), "~", False))
    End Sub



  5. #5
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Remove text between quotes, variable length and number of quotes

    Ah, snb, we don't seem to have been in a thread together for a while. I've missed you, but then I've a real soft spot for any line of code that begins Join(Filter(Split(Replace

  6. #6
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Remove text between quotes, variable length and number of quotes

    Not to mention where my soft spots lie....

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1