Results 1 to 4 of 4
  1. #1
    New Lounger
    Join Date
    Dec 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Convert table that is 366x25 to one that is 2x8761

    I have multiple tables that I need to convert. Currently, days are in rows and 24 hours are in the columns. I need to convert the table so that days and hours are both in the rows. For example, the old rows are day 1, day 2, day 3, etc. The new rows would be day 1 hour 1, day 1 hour 2, day 1 hour 3, etc. Someone suggested a macro but I know very little about them. Any help would be greatly appreciated. Cheers- Russell

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Convert table that is 366x25 to one that is 2x8761

    Welcome to Woody's Lounge!

    Try this macro:

    Sub ConvertDateTime()
    Dim wshIn As Worksheet
    Dim wshOut As Worksheet
    Dim r As Long
    Dim c As Long
    Dim n As Long
    Application.ScreenUpdating = False
    Set wshIn = ActiveSheet
    Set wshOut = Worksheets.Add(After:=wshIn)
    wshOut.Range("A1") = wshIn.Range("A1")
    wshOut.Range("B1") = "Value"
    For r = 2 To 366 ' days
    For c = 2 To 25 ' hours
    n = 24 * (r - 2) + c
    wshOut.Cells(n, 1) = wshIn.Cells(r, 1)
    wshOut.Cells(n, 2) = wshIn.Cells(r, c)
    Next c
    Next r
    wshOut.Columns(1).NumberFormat = "m/d/yyyy"
    Application.ScreenUpdating = True
    End Sub

  3. #3
    New Lounger
    Join Date
    Dec 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Convert table that is 366x25 to one that is 2x

    That is fantastic. It worked perfectly. This is my first time on this board and I

  4. #4
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Convert table that is 366x25 to one that is 2x

    Welcome to the Lounge. Good to have you aboard.
    Legare Coleman

Posting Permissions

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