+ Reply to Thread
Results 1 to 5 of 5

How to "Text to column" by Macro ?

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-08-2012
    Location
    BD
    MS-Off Ver
    Microsoft Office 2016
    Posts
    640

    How to "Text to column" by Macro ?

    If cell A1 contains numbers 123456 , now I need macro for “Text to column”
    Required separation for every digit like bellow
    B1= 1
    C1= 2
    D1= 3
    E1= 4
    F1= 5
    G1= 6

    like wise If cell A1 contains numbers ABCDEF, then it will like below

    B1= A
    C1= B
    D1= C
    E1= D
    F1= E
    G1= F

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

    Re: How to "Text to column" by Macro ?

    Why macro?

    B1:
    =MID($A$1,COLUMN(A1),1)
    and copy right.

    If you insist
    Sub test()
        With Range("a1")
            .Cells(, 2).Resize(, Len(.Value)) = Split(StrConv(.Value, 64), Chr(0))
        End With
    End Sub
    Last edited by jindon; 12-09-2012 at 02:13 AM.

  3. #3
    Forum Contributor
    Join Date
    06-08-2012
    Location
    BD
    MS-Off Ver
    Microsoft Office 2016
    Posts
    640

    Re: How to "Text to column" by Macro ?

    Hi Jindon ,Because I have another module , and I want to run both module together.
    However both(formula & macro) are working fine…Thanks...

  4. #4
    Registered User
    Join Date
    12-02-2012
    Location
    Delhi
    MS-Off Ver
    Excel 2003,2007
    Posts
    17

    Re: How to "Text to column" by Macro ?

    Hi,

    you can achieve your objective with the below code: try this.. Please make the changes for the data range

    Sub modTexttoColumn()
        Dim rngData As Range
        Dim varData As Variant
        Dim lngCount As Long
        Dim lngMaxLen As Long
        Dim varOutput As Variant
        Dim lngChartLen As Long
        
        Set rngData = ThisWorkbook.Worksheets("Sheet1").Range("A1:A10")
        If rngData.Columns.Count = 1 Then
            varData = rngData
            For lngCount = LBound(varData) To UBound(varData)
                If Len(varData(lngCount, 1)) > lngMaxLen Then
                    lngMaxLen = Len(varData(lngCount, 1))
                End If
            Next
        End If
        
        ReDim varOutput(1 To rngData.Rows.Count, 1 To lngMaxLen)
        For lngCount = LBound(varData) To UBound(varData)
            For lngChartLen = 1 To Len(varData(lngCount, 1))
                varOutput(lngCount, lngChartLen) = Mid(varData(lngCount, 1), lngChartLen, 1)
            Next
        Next
        rngData.Cells(1, 1).Resize(UBound(varOutput, 1), UBound(varOutput, 2)) = varOutput
        
    End Sub

  5. #5
    Forum Contributor
    Join Date
    06-08-2012
    Location
    BD
    MS-Off Ver
    Microsoft Office 2016
    Posts
    640

    Re: How to "Text to column" by Macro ?

    Hi excel-walker, it also works fine ...thanks..

+ 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