+ Reply to Thread
Results 1 to 6 of 6

Splitting string and distributing to columns with VBA (conditional)

  1. #1
    Registered User
    Join Date
    07-03-2012
    Location
    Norge
    MS-Off Ver
    Excel 2010
    Posts
    40

    Splitting string and distributing to columns with VBA (conditional)

    Hi everyone,

    I'm completely lost when it comes to VBA, and now I need a new function/subroutine to use in a bigger VBA-project in Excel.

    I have one column that has data corresponding to the column "Original" below.
    For each cell in column "Original", I would need to split it as the table shows.

    The original must be left untouched. Original can have a varying amount of letters in the beginning, and those starting with SG does not have any dash between the digits.
    Original I J K L
    CE 10-001-0002-001 10 001 0002 001
    CE 10-001-0005-001 10 001 0005 001
    TCE 23-004-3602-001 23 004 3602 001
    TCE 24-001-2810-001 24 001 2810 001
    TP 60-000-0001-101 60 0000 0001 101
    TROLLEY 60-000-0020-000 60 000 0020 000
    SG 23004 23 004

    Constraints/wishes
    • Needs to be called as a subroutine
    • Should accept work on column G in ActiveSheet.

    I thought about stripping the original for all non numeric characters, but was not desirable.
    Then I guess it would be easy to just do a R1C1 reference and get substrings from the original cell.

    The following is a solution I'm using in another of the subroutines that is called:

    Please Login or Register  to view this content.
    Please see the attached file for some example data.
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: Splitting string and distributing to columns with VBA (conditional)

    Try this

    Please Login or Register  to view this content.
    Elegant Simplicity............. Not Always

  3. #3
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Splitting string and distributing to columns with VBA (conditional)

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    07-03-2012
    Location
    Norge
    MS-Off Ver
    Excel 2010
    Posts
    40

    Re: Splitting string and distributing to columns with VBA (conditional)

    This solution worked perfectly!

    Please Login or Register  to view this content.
    Would there be much that needs to change if the SG 23000 format should also fill in 0000 (K) and 000 (L) in the remaining columns?

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Splitting string and distributing to columns with VBA (conditional)

    Do you mean
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    07-03-2012
    Location
    Norge
    MS-Off Ver
    Excel 2010
    Posts
    40

    Re: Splitting string and distributing to columns with VBA (conditional)

    Hi jindon, sorry for the delay in coming back to you. This solved the last part of it.
    I really appreciate your efforts!

    Best regards,
    Knut

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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