Consulting

Results 1 to 5 of 5

Thread: Solved: extract a column to 5 column

  1. #1
    VBAX Tutor
    Joined
    Sep 2007
    Posts
    265
    Location

    Solved: extract a column to 5 column

    Hi there,

    I need a vba code to extract a column to 5 column.

    First Row data in Column K will be extract to column M
    Second Row data in colum K will be extract to column N
    and so on.

    Thanks for assistance, rgds. Harto

    See the attachement for you reference.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Public Sub ProcessData()
    Const TEST_COLUMN As String = "K" '<=== change to suit
    Dim i As Long, j As Long
    Dim LastRow As Long
    Dim Breaks As Variant
    Dim NumItems As Long

    With Application

    .ScreenUpdating = False
    .Calculation = xlCalculationManual
    End With

    With ActiveSheet

    LastRow = .Cells(.Rows.Count, TEST_COLUMN).End(xlUp).Row
    For i = 2 To LastRow

    Breaks = Split(.Cells(i, TEST_COLUMN).Value, Chr(10))
    NumItems = UBound(Breaks) - LBound(Breaks) + 1
    .Cells(i, TEST_COLUMN).Offset(0, 1).Resize(, NumItems) = Breaks
    Next
    End With

    With Application

    .Calculation = xlCalculationAutomatic
    .ScreenUpdating = True
    End With

    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Tutor
    Joined
    Sep 2007
    Posts
    265
    Location
    Hi Bob,
    Work fine, and thank you so much.
    Your very helpful person.

    Best regards, Harto

  4. #4
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,198
    Location
    Too slow again... Here is where i got to just for info.

    [vba]Function WrapToLines(rCell As Range, Line As Long)
    Dim Str1 As Variant

    Str1 = Split(Replace(rCell.Value, Chr(10), "~"), "~")

    WrapToLines = Str1(Line - 1)

    End Function[/vba]
    Use like...

    =WrapToLines(A1,1)
    =WrapToLines(A1,2)
    =WrapToLines(A1,3)
    and so on
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved
    Click here for a guide on how to upload a file with your post

    Excel 365, Version 2403, Build 17425.20146

  5. #5
    VBAX Tutor
    Joined
    Sep 2007
    Posts
    265
    Location
    Hi Georgiboy

    Thanks so much, appreciate it.

    Rgds, Harto

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •