+ Reply to Thread
Results 1 to 12 of 12

VBA Code to split cell's text data

Hybrid View

  1. #1
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: VBA Code to split cell's text data

    Hi,
    Here is macro that
    split value in column F
    populate column A
    Populate column E
    populate B with VLOOKUP formula that retrieves data from the other sheet

    Sub SplitString()
        Dim cl As Range
        Dim vSplitString As Variant
        Dim intIndex As Integer
        Dim strName As String
        Dim rngEMails As Range
        
        With Worksheets("Email ID Data")
            Set rngEMails = .Range("A1").Resize(.Range("A" & _
                                                       Rows.Count).End(xlUp).Row, 2)
        End With
    
        For Each cl In Range("F2:F" & Range("F" & Rows.Count).End(xlUp).Row)
            vSplitString = VBA.Split(cl.Value, "\")
            intIndex = UBound(vSplitString)
            strName = vSplitString(intIndex)
            Range("A" & cl.Row).Value = Left(strName, InStrRev(strName, ".") - 1)    'Name
            Range("E" & cl.Row).Value = vSplitString(intIndex - 1)  'Subject
            Range("B" & cl.Row).FormulaR1C1 = "=VLOOKUP(RC1," & _
                rngEMails.Address(True, True, xlR1C1, True) & ",2,False)"
        Next cl
    
    End Sub
    If you are pleased with a member's answer then use the Star icon to rate it.

  2. #2
    Registered User
    Join Date
    12-19-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    53

    Re: VBA Code to split cell's text data

    Thanks Buran for quick response !!

    Is it possible to split path like "C:\Documents and Settings\liz\Desktop\INST\UID_August_Baker,Edward D.xlsx" into two parts?
    Name (Column A) "Baker,Edward D" and Subject (Column E) "UID_August". Rest condition would be same.

    Also we can't use vlookup as this fails once it search same value again.

  3. #3
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: VBA Code to split cell's text data

    Quote Originally Posted by Liz_Biz View Post
    Is it possible to split path like "C:\Documents and Settings\liz\Desktop\INST\UID_August_Baker,Edward D.xlsx" into two parts?
    Name (Column A) "Baker,Edward D" and Subject (Column E) "UID_August". Rest condition would be same.
    Yes, it's possible but you should specify where to split (e.g. at last underscore)

    Quote Originally Posted by Liz_Biz View Post
    Also we can't use vlookup as this fails once it search same value again.
    I don't understand waht you mean with that. Can you explain further. You can always convert formula to value...

  4. #4
    Registered User
    Join Date
    12-19-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    53

    Re: VBA Code to split cell's text data

    Yes. It's last underscore.

    Sorry !! vlookup is working fine. Can we remove this vlookup formula and past only value?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Split data with vba code after every comma.
    By a1b2c3d4e5f6g7 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-28-2014, 11:50 AM
  2. VB Code to split the text String
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-25-2013, 10:21 AM
  3. [SOLVED] VB Code to split data
    By Oszie in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 11-27-2013, 08:37 AM
  4. how to convert excel split code to word split code
    By gsrikanth in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-02-2012, 07:56 AM
  5. Mod code to split text
    By karinos57 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-25-2007, 10:27 PM

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