Results 1 to 3 of 3

Thread: seprate data in rows to columns

  1. #1
    Junior Member
    Join Date
    Feb 2014
    Posts
    24
    Rep Power
    0

    seprate data in rows to columns

    Attachment 1508hi
    i have data like below
    time time time time
    2014/03/01 05:15 0.7 11:31 4 17:24 0.5
    2014/03/02 00:04 4.3 05:59 0.5 12:19 3.9 18:08 0.6
    2014/03/03 00:49 4.4 06:40 0.5 13:03 3.8 18:51 0.7
    2014/03/04 01:31 4.4 07:21 0.5 13:49 3.7 19:33 1
    2014/03/05 02:11 4.3 08:02 0.6 14:40 3.5 20:16 1.2
    2014/03/06 02:47 4.1 08:41 0.7 15:44 3.3 21:02 1.6
    2014/03/07 03:23 3.9 09:18 0.9 16:53 3.1 21:56 1.8
    i want to have data with vb code like
    2014/03/01 05:15 0.7
    2014/03/01 11:31 4
    2014/03/01 17:24 0.5
    2014/03/02 00:04 4.3
    2014/03/02 05:59 0.5
    ..................................
    ................................

  2. #2

  3. #3
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    Hi

    Try this

    Code:
    Option Explicit
    
    Sub kTest()
        
        Dim k, ka(), i As Long, n As Long, c As Long, Sht As Worksheet
        
        k = Range("a1").CurrentRegion.Value2    '<<< adjust the range
        
        ReDim ka(1 To UBound(k, 1) * UBound(k, 2), 1 To 3)
        
        For i = 2 To UBound(k, 1) 'skip the header row
            If Len(k(i, 1)) Then
                For c = 2 To UBound(k, 2) - 1 Step 2
                    n = n + 1
                    ka(n, 1) = k(i, 1)
                    ka(n, 2) = k(i, c)
                    ka(n, 3) = k(i, c + 1)
                Next
            End If
        Next
        
        If n Then
            On Error Resume Next
            Set Sht = Worksheets("Output_")
            Err.Clear: On Error GoTo 0
            If Sht Is Nothing Then
                Worksheets.Add.Name = "Output_"
                Set Sht = ActiveSheet
            End If
            
            With Sht
                .Range("a1:c1") = [{"Date","Time","Value"}]
                .Range("a2").Resize(n, UBound(ka, 2)).Value = ka
                .Range("a2").Resize(n).NumberFormat = "yyyy/mm/dd"
                .Range("b2").Resize(n).NumberFormat = "[h]:mm"
            End With
        End If
        
    End Sub
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

Similar Threads

  1. Replies: 10
    Last Post: 08-31-2013, 06:56 PM
  2. Replies: 6
    Last Post: 08-14-2013, 04:25 PM
  3. Replies: 3
    Last Post: 07-29-2013, 11:32 PM
  4. Move data from rows into columns for every unique value
    By mahmoud-lee in forum Excel Help
    Replies: 4
    Last Post: 06-13-2013, 03:02 AM
  5. Replies: 4
    Last Post: 05-01-2013, 09:49 PM

Posting Permissions

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