+ Reply to Thread
Results 1 to 4 of 4

Split 1column into 2 columns VBA

Hybrid View

  1. #1
    Registered User
    Join Date
    10-16-2012
    Location
    china
    MS-Off Ver
    Excel 2007
    Posts
    8

    Split 1column into 2 columns VBA

    Dear All,

    I've been looking it up in here then trying it with the code I found, but I cant manage to get my vba to work correctly. Could you please help me to find a code to split data from 1 column into 2 please?
    I have

    Column H
    1/12/2012-1/12/2012
    1/12/2012-2/4/2012
    1/9/2012-1/13/2012
    1/11/2012-1/31/2012
    1/11/2012-1/31/2012
    1/11/2012-1/31/2012
    1/28/2012-2/8/2012
    2/7/2012-2/22/2012

    And I would like to have

    Column G Column I
    1/12/2012 1/12/2012
    1/12/2012 2/4/2012
    1/9/2012 1/13/2012
    1/11/2012 1/31/2012
    1/11/2012 1/31/2012
    1/11/2012 1/31/2012
    1/28/2012 2/8/2012
    2/7/2012 2/22/2012


    I used
    = Left(H5, FIND("-", H5) - 1)
    = Right(H5, FIND("-", H5) - 1)

    But sometimes for the "column I", I get " -1/12/2012"...

    If you have an idea of how to write a vba code that can be applied in the Range "H5:H5000" , please don't hesitate! Thank you everyone
    Last edited by svmt; 11-27-2012 at 05:12 AM.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    Use Data>Text to columns... with - as the delimiter.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    06-07-2012
    Location
    INDIA
    MS-Off Ver
    Excel 2003,2007
    Posts
    1

    Re: Split 1column into 2 columns VBA

    Sub text2columns()


    Dim myrng As Range
    Dim rng As Range

    Set myrng = Range("H5:H5000")

    For Each rng In myrng

    On Error Resume Next
    rng.Offset(0,-1) = VBA.Left(rng, WorksheetFunction.Search("-", rng) - 1)
    rng.Offset(0, 1) = VBA.Right(rng, VBA.Len(rng) - WorksheetFunction.Search("-", rng))

    Next rng


    End Sub

  4. #4
    Registered User
    Join Date
    10-16-2012
    Location
    china
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Split 1column into 2 columns VBA

    Thank you so much!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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