Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: How To Split A Text Based On Two Special Characters

  1. #1
    Member Charles's Avatar
    Join Date
    Aug 2012
    Posts
    63
    Rep Power
    12

    How To Split A Text Based On Two Special Characters

    Hi,

    I can usually solve my problems. But, in this case I may be having a "CRAFT" moment.
    What I'm trying to do is split a string form this

    Code:
    c.2339A>A/C; p.N780T
    to

    Code:
    c.2339A>C
    I know its something simple but...

    Thank for any help.

    I'm looking for VBA.

    HI. I also have this posted on:

    http://www.mrexcel.com/forum/excel-q...ml#post3930583
    Last edited by Charles; 09-08-2014 at 01:10 AM. Reason: Posted else where
    If you like the answer, please click " * " below Member name to say thanks.

  2. #2
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,401
    Rep Power
    10
    Charles, the link doesn't seem to be pointing to the right thread

    Anyway, your resultant text
    c.2339A>C

    seems to be different from what one would expect if it were a split with the semicolon (

    So is there something beyond that, or is it just a typo?
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  3. #3
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,401
    Rep Power
    10
    OK, got more information from the other thread regarding your problem. Can you paste the following code to a code module, and try calling the UDF function to solve your issue.



    Code:
    Function CSPLIT(strPassed As String) As String
    
        Dim str, strP As String
        strP = Split(strPassed, ";")(0)
        str = Split(strP, ">")(0) & ">"
        If InStr(1, Split(strPassed, ";")(0), "/") Then
            str = str & Split(Split(strPassed, ";")(0), "/")(1)
        Else
            str = str & Right(Split(strPassed, ";")(0), 1)
        End If
        CSPLIT = str
        
    End Function
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  4. #4
    Senior Member
    Join Date
    Jun 2012
    Posts
    337
    Rep Power
    13
    Code:
    sub M_snb()
       msgbox F_snb("c.639T>C; p.D213D")
    end sub
    
    function F_snb(c00)
      f_snb=split(split(c00,";")(0),"/")(0)
    function end

  5. #5
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    659
    Rep Power
    13
    Here is a macro that does what I think you want...
    Code:
    Sub ParseMedicalCodes()
       With Range("A1", Cells(Rows.Count, "A").End(xlUp))
         .Copy .Offset(, 1)
         .Offset(, 1).Replace ";*", "", xlPart
         .Offset(, 1).Replace ">*/", ">", xlPart
       End With
     End Sub

  6. #6
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,401
    Rep Power
    10
    hi snb, could you check your formula again... it doesn't seem to be satisfying one of the requirements OP has mentioned in the other forum.
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  7. #7
    Senior Member
    Join Date
    Jun 2012
    Posts
    337
    Rep Power
    13
    I don't provide solutions, only suggestions for methods to attain a certain goal. The OP can adapt anything I suggest.
    Last edited by snb; 09-09-2014 at 02:22 PM.

  8. #8
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,401
    Rep Power
    10
    Sure. Thanks snb.
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  9. #9
    Member Charles's Avatar
    Join Date
    Aug 2012
    Posts
    63
    Rep Power
    12
    Hi,

    Thanks to all who helped.
    With the help this is the final code that I came up with.

    Code:
    Sub Refseq()
    Dim Mval As String
    Dim i As Long
    Dim lrow As Long
    Sheets("Sheet2").Activate
    lrow = Sheets("Sheet2").Range("A65536").End(xlUp).Row
    For i = 2 To lrow
        Range("G" & i) = Range("F" & i) & ":" & CSPLIT(Range("B" & i))
    Next
    End Sub
    
    Function CSPLIT(strPassed As String) As String
    
        Dim str, strP As String
        strP = Split(strPassed, ";")(0)
        str = Split(strP, ">")(0) & ">"
        If InStr(1, Split(strPassed, ";")(0), "/") Then
            str = str & Split(Split(strPassed, ";")(0), "/")(1)
        Else
            str = str & Right(Split(strPassed, ";")(0), 1)
        End If
        CSPLIT = str
        
    End Function
    If you like the answer, please click " * " below Member name to say thanks.

  10. #10
    Senior Member
    Join Date
    Jun 2012
    Posts
    337
    Rep Power
    13
    I came up with:

    Code:
    Function F_snb(c00)
        F_snb = Split(c00, ">")(0) & ">" & Replace(Filter(Split(Replace(Replace(c00, ">", "/"), ";", "~/"), "/"), "~")(0), "~", "")
    End Function
    Last edited by snb; 09-10-2014 at 12:16 PM.

Similar Threads

  1. Replies: 3
    Last Post: 02-24-2014, 05:48 AM
  2. Remove Special Characters From Text Or Remove Numbers From Text
    By Excel Fox in forum Excel and VBA Tips and Tricks
    Replies: 5
    Last Post: 05-31-2013, 04:43 PM
  3. Replies: 5
    Last Post: 05-28-2013, 03:00 AM
  4. Replies: 4
    Last Post: 05-01-2013, 09:49 PM
  5. Remove Special Characters :
    By Rajan_Verma in forum Rajan Verma's Corner
    Replies: 3
    Last Post: 03-06-2012, 09:41 PM

Posting Permissions

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