+ Reply to Thread
Results 1 to 5 of 5

Convert Data to diff format (see attached)

Hybrid View

  1. #1
    Forum Contributor pr4t3ek's Avatar
    Join Date
    10-13-2008
    Location
    Melbourne, Australia
    MS-Off Ver
    2003 & 2007, 2010
    Posts
    483

    Convert Data to diff format (see attached)

    Hi,
    Please see the attached file.

    In the RawData tab, I have the Type, The Date, and total for that date and type.

    Using a macro, i would like to redesign the output(onto another sheet) so it can be updated to a database table(i already have the code to export to database). The output should look like what is in the "OutputExample" tab.

    Figures in the OutputExample tab are only for the first three dates.

    So currently, I have the output as:
    Date Type1Total, Type2 Total, Type3 Total, Type4 Total.
    
    I would like to re-arrange so it shows it as:
    Type1 Date Type1Total
    Type2 Date Type2Total
    Type3 Date Type3Total
    Type4 Date Type4Total
    please see the attached file to see this from a data perspective..

    Most importantly: Because the attached is only an example, If we could get the TypeName(e.g. Type1, Type2, Type3, Type4) from the Raw sheet and the date from the rawsheet + figures also.

    Please let me know if there are any questions in relation to this.

    Thank you

    PS: I need a macro to do this only because ive got like 7 sheets to do & each sheet has around 4k rows each.
    Attached Files Attached Files
    Last edited by pr4t3ek; 05-11-2009 at 03:47 AM.
    --
    Regards
    PD

    ----- Don't Forget -----

    1. Use code tags. Place "[code]" before the first line of code and "[/code"]" after the last line of code. Exclude quotation marks

    2. Thank those who have helped you by Clicking the scales above each post.

    3. Please mark your post [SOLVED] if it has been answered satisfactorily.

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Convert Data to diff format (see attached)

    Based on your example - perhaps:

    Public Sub Transpose()
    Dim lngRw As Long, lngRwOut As Long, wsIn As Worksheet, wsOut As Worksheet
    Set wsIn = Sheets("RawData")
    Set wsOut = Sheets("OutputExample)
    lngRwOut = 2
    wsIn.Activate
    For lngRw = lngRwOut To wsIn.Cells(Rows.Count, "A").End(xlUp).Row Step 1
        wsOut.Cells(lngRwOut, "A").Resize(4).Value = Application.Transpose(wsIn.Range(Cells(1, "B"), Cells(1, "E")))
        wsOut.Cells(lngRwOut, "B").Resize(4).Value = wsIn.Cells(lngRw, "A")
        wsOut.Cells(lngRwOut, "C").Resize(4).Value = Application.Transpose(wsIn.Cells(lngRw, "B").Resize(, 4).Value)
        lngRwOut = lngRwOut + 4
    Next lngRw
    Set wsIn = Nothing
    Set wsOut = Nothing
    End Sub

  3. #3
    Forum Contributor pr4t3ek's Avatar
    Join Date
    10-13-2008
    Location
    Melbourne, Australia
    MS-Off Ver
    2003 & 2007, 2010
    Posts
    483

    Re: Convert Data to diff format (see attached)

    excellent!!
    now, can i just add one extra thing..

    How can i amend your code so that it looks in the RawData sheet and see's how many Types there are.

    e.g. In my real data, ive infact got 37 Type's, not 4..
    And in another sheet, ive got 50 odd etc.

    So how can we make it so that it looks at how many types are...

    maybe by looking at how columns have a value except column A?

    cheers mate!

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Convert Data to diff format (see attached)

    Assuming no blanks interspersed amongst the headers then:

    Public Sub Transpose()
    Dim lngRw As Long, lngRwOut As Long, wsIn As Worksheet, wsOut As Worksheet, lngCols As Long
    Set wsIn = Sheets("RawData")
    Set wsOut = Sheets("Sheet1")
    wsIn.Activate
    lngRwOut = 2
    lngCols = Cells(1, Columns.Count).End(xlToLeft).Column - 1
    For lngRw = lngRwOut To wsIn.Cells(Rows.Count, "A").End(xlUp).Row Step 1
        wsOut.Cells(lngRwOut, "A").Resize(lngCols).Value = Application.Transpose(wsIn.Range(Cells(1, "B"), Cells(1, lngCols + 1)))
        wsOut.Cells(lngRwOut, "B").Resize(lngCols).Value = wsIn.Cells(lngRw, "A")
        wsOut.Cells(lngRwOut, "C").Resize(lngCols).Value = Application.Transpose(wsIn.Cells(lngRw, "B").Resize(, lngCols).Value)
        lngRwOut = lngRwOut + lngCols
    Next lngRw
    Set wsIn = Nothing
    Set wsOut = Nothing
    End Sub

  5. #5
    Forum Contributor pr4t3ek's Avatar
    Join Date
    10-13-2008
    Location
    Melbourne, Australia
    MS-Off Ver
    2003 & 2007, 2010
    Posts
    483

    Re: Convert Data to diff format (see attached)

    exceelllent, working perfectly that is!! =]

+ 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