+ Reply to Thread
Results 1 to 16 of 16

Split up a cell by every ;

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-07-2014
    Location
    Göteborg
    MS-Off Ver
    2010
    Posts
    130

    Split up a cell by every ;

    I got a problem which is outside of my comfortzone so I was thinking about asking for help here. I got a datafile which is attached below with a examplefile as how the data can look like. In the first sheet is how the data looks like and the second sheet is instead how I would like to have the data after my macro.

    Every datarow has all their data in one row which is the problem. For example A5 might look like this; 860528306;201513;KXDPBO08;2015151;VP11K ;53;

    What I want to do is the following?
    From row 5 to the lastrow, I want to split up the first column (A5,A6,A7...and so on) with every ; character.
    Therefore the example of 860528306;201513;KXDPBO08;2015151;VP11K ;53; would be the following:

    Cell("A2")=860528306
    Cell("B2")=201513
    Cell("C2")=KXDPBO08
    Cell("D2")=2015151
    Cell("E2")=VP11K
    Cell("F2")=53

    As you can see the last ; character is just an end of the data. There might also be spaces in the data so I would have to trim the cells.
    I haven't done any code with splitting up cells so I would be very happy if anyone could help me.
    Attached Files Attached Files

  2. #2
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Split up a cell by every ;

    Use this, copied across and down:

    =TRIM(MID(SUBSTITUTE(";"&'Sheet1-Before'!$A5,";",REPT(" ",125)),125*COLUMNS($A:A),125))
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU

  3. #3
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Split up a cell by every ;

    Since you're in Sweden, you'll probably need this:

    =TRIM(MID(SUBSTITUTE(";"&'Sheet1-Before'!$A5;";",REPT(" ";125));125*COLUMNS($A:A);125))

    using ; as a separator, not the , that the rest of us use...

  4. #4
    Forum Contributor
    Join Date
    07-07-2014
    Location
    Göteborg
    MS-Off Ver
    2010
    Posts
    130

    Re: Split up a cell by every ;

    Thx for your quick answer. Where should I copy this formula?

  5. #5
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Split up a cell by every ;

    There is an excel function called "Text To columns". Use semi-colon as a separator and you are home and dry.

  6. #6
    Forum Contributor
    Join Date
    07-07-2014
    Location
    Göteborg
    MS-Off Ver
    2010
    Posts
    130

    Re: Split up a cell by every ;

    I see! I got it to work in column A but what about column B, do I have to change the formula?

  7. #7
    Forum Contributor
    Join Date
    07-07-2014
    Location
    Göteborg
    MS-Off Ver
    2010
    Posts
    130

    Re: Split up a cell by every ;

    AB33; Oh I didn't know that function. Thank you very much!

  8. #8
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Split up a cell by every ;

    Sub Text2Columns()
        
        Rows("1:2").Delete Shift:=xlUp
        Rows("2:2").Delete Shift:=xlUp
        
        Columns("A:A").Replace What:=" ", Replacement:="", LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False
            
        Columns("A:A").TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
            TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
            Semicolon:=True, Comma:=False, Space:=False, Other:=False, FieldInfo _
            :=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), _
            Array(7, 1)), TrailingMinusNumbers:=True
        
        Range("A1").CurrentRegion.AutoFilter
        
        Columns("A:A").EntireColumn.AutoFit
        Columns("B:B").ColumnWidth = 12.22
        Columns("C:C").ColumnWidth = 9.11
        Columns("D:D").ColumnWidth = 10.56
        Columns("E:E").ColumnWidth = 10.67
        Columns("F:F").ColumnWidth = 7.11
        
    End Sub
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  9. #9
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Split up a cell by every ;

    Anywhere at all. I tested it in your AFTER sheet, cell A2

  10. #10
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: Split up a cell by every ;

    This can be easily achieved with the help of Text to Columns inbuilt feature as suggested by AB33.

    Follow these steps to achieve the desired output...

    On Sheet Sheet1-Before

    1) Delete rows 1, 2 and 4.

    2) Select whole column A.

    3) On Data Tab --> Text to Columns --> Make sure Delimited radio button is selected --> Next --> Select Semicolon under Delimiters options --> Next --> Finish

    That's it.
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  11. #11
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    90,972

    Re: Split up a cell by every ;

    Unfortunately, in this instance, text to columns does not completely fulfil the brief because it will not get rid of trailing spaces:

    As you can see the last ; character is just an end of the data. There might also be spaces in the data so I would have to trim the cells.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  12. #12
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Split up a cell by every ;

    Quote Originally Posted by AliGW View Post
    Unfortunately, in this instance, text to columns does not completely fulfil the brief because it will not get rid of trailing spaces:
    I used the Replace function to remove spaces. See my code in post #8.

  13. #13
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: Split up a cell by every ;

    You have a point here Ali. Didn't read the original post carefully.
    But the extra spaces can be removed at once from all the data with another inbuilt feature called Replace which can be invoked with Ctrl+H
    Last edited by AliGW; 12-22-2016 at 09:13 AM.

  14. #14
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    90,972

    Re: Split up a cell by every ;

    Yes, sure it can, but it means a two-stage process, whereas the other two solutions offered are one-stage.

    @AlphaFrog - your VBA solution was not being referred to - it was AB33 and Sktneer's proposals.
    Last edited by AliGW; 12-22-2016 at 09:15 AM.

  15. #15
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: Split up a cell by every ;

    Quote Originally Posted by AliGW View Post
    Yes, sure it can, but it means a two-stage process, whereas the other two solutions offered are one-stage.

    @AlphaFrog - your VBA solution was not being referred to - it was AB33 and Sktneer's proposals.
    You have a brilliant future Ali!

  16. #16
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    90,972

    Re: Split up a cell by every ;

    Quote Originally Posted by sktneer View Post
    You have a brilliant future Ali!
    LOL!!!

+ 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. Need Macro code to split data split in 7 sheets based on variable rows in column A
    By Alija_21 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-31-2015, 08:03 AM
  2. [SOLVED] create macro to split screen and then in top split, go to a certain cell
    By ammartino44 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-17-2015, 05:45 PM
  3. Split cell to create sorted heading on empty row above and keep second split info
    By CastingDirector in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-09-2015, 12:24 AM
  4. [SOLVED] Split Array, Listing Marked Items in Split Arrays
    By lesoies in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-27-2013, 02:07 AM
  5. [SOLVED] Split Macro modification to Split into new Workbooks instead of sheets within one workbook
    By DLSmith in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-13-2012, 08:11 PM
  6. Macro : Split text of a single cell into multiple cell
    By rampal in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-03-2012, 02:05 PM
  7. Can excels Split() function split a string up at multiple spots?
    By 111StepsAhead in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-14-2011, 02:36 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