+ Reply to Thread
Results 1 to 6 of 6

Macro - text to column and copy the information in the next row and loop until finish

Hybrid View

  1. #1
    Registered User
    Join Date
    11-01-2011
    Location
    malaysia
    MS-Off Ver
    Excel 2003
    Posts
    5

    Macro - text to column and copy the information in the next row and loop until finish

    Hi, can you please help to create macro, see example below:

    In column G, 1st row is contains more than 1 data (343376, 487381), therefore, i need this to split and copy down the same information in another row.
    Can you help on this...


    Original:

    Column A Column B Column C Column D Columm E Column F Column G
    Australia A.C.N. GB 0000418 GBC 0001738 343376, 487381
    Australia A.P.M. GB 0000418 GBN 0001747 169038

    Result:

    Column A Column B Column C Column D Columm E Column F Column G
    Australia A.C.N. GB 0000418 GBC 0001738 343376
    Australia A.C.N. GB 0000418 GBC 0001738 487381
    Australia A.P.M. GB 0000418 GBN 0001747 169038

  2. #2
    Forum Expert
    Join Date
    06-09-2010
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    1,714

    Re: Macro - text to column and copy the information in the next row and loop until finish

    Hi
    is 343376, 487381 in cell G1, or is 343376 in G1 and 487381 in H1
    if the former, are they always in column G, and are they always separated by a comma and space
    uploading a workbook with an example of what you want might help

  3. #3
    Registered User
    Join Date
    11-01-2011
    Location
    malaysia
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Macro - text to column and copy the information in the next row and loop until finish

    Hi, is 343376, 487381 in cell G1. I attached the file already. Thanks
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    06-09-2010
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    1,714

    Re: Macro - text to column and copy the information in the next row and loop until finish

    Hi
    try this macro
    Sub split_cells()
    Dim ArrNos As Variant, RowNum As Long, x As Long, y As Long
    RowNum = 2
    Do While Rows(RowNum).Columns("G").Value <> ""
        ArrNos = split(Rows(RowNum).Columns("G").Value, ",")
        If UBound(ArrNos) > 0 Then
            Rows(RowNum).Columns("G").Value = ArrNos(0)
            For x = 1 To UBound(ArrNos)
              RowNum = RowNum + 1
              Rows(RowNum).EntireRow.Insert
              Rows(RowNum).Columns("G").Value = ArrNos(x)
              For y = 1 To 6
                Rows(RowNum).Columns(y) = Rows(RowNum - 1).Columns(y)
                'Rows(RowNum).Columns(y).NumberFormat = Rows(RowNum - 1).Columns(y).NumberFormat
              Next y
            Next x
        End If
        RowNum = RowNum + 1
    Loop
    End Sub

  5. #5
    Registered User
    Join Date
    11-01-2011
    Location
    malaysia
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Macro - text to column and copy the information in the next row and loop until finish

    Hi Nicky, i find there is some blank space in result column G. Can we use TRIM formula to incorporate in ur macro to remove it?

  6. #6
    Forum Expert
    Join Date
    06-09-2010
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    1,714

    Re: Macro - text to column and copy the information in the next row and loop until finish

    yes - try this:
    Sub split_cells()
    Dim ArrNos As Variant, RowNum As Long, x As Long, y As Long
    RowNum = 2
    Do While Rows(RowNum).Columns("G").Value <> ""
        ArrNos = Split(Rows(RowNum).Columns("G").Value, ",")
        If UBound(ArrNos) > 0 Then
            Rows(RowNum).Columns("G").Value = Trim(ArrNos(0))
            For x = 1 To UBound(ArrNos)
              RowNum = RowNum + 1
              Rows(RowNum).EntireRow.Insert
              Rows(RowNum).Columns("G").Value = Trim(ArrNos(x))
              For y = 1 To 6
                Rows(RowNum).Columns(y) = Rows(RowNum - 1).Columns(y)
                'Rows(RowNum).Columns(y).NumberFormat = Rows(RowNum - 1).Columns(y).NumberFormat
              Next y
            Next x
        End If
        RowNum = RowNum + 1
    Loop
    End Sub

+ 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