Results 1 to 6 of 6

Splitting string and distributing to columns with VBA (conditional)

Threaded View

  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:

        Range("A2").Select
        ActiveCell.FormulaR1C1 = "=MONTH(RC[3])"
        Range("A2").Select
        Selection.AutoFill Destination:=Range(Cells(2, 1), Cells(w, 1)), Type:=xlFillDefault
        Range("B2").Select
        ActiveCell.FormulaR1C1 = "=DAY(RC[2])"
        Range("B2").Select
        Selection.AutoFill Destination:=Range(Cells(2, 2), Cells(w, 2))
        Range("C2").Select
        ActiveCell.FormulaR1C1 = "=HOUR(RC[1])"
        Range("C2").Select
        Selection.AutoFill Destination:=Range(Cells(2, 3), Cells(w, 3))
    Please see the attached file for some example data.
    Attached Files Attached Files

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