+ Reply to Thread
Results 1 to 6 of 6

Help with Transposing Code

Hybrid View

Gustavus Help with Transposing Code 10-31-2012, 05:17 PM
rylo Re: Help with Transposing Code 10-31-2012, 09:07 PM
Gustavus Re: Help with Transposing Code 11-02-2012, 01:02 AM
rylo Re: Help with Transposing Code 11-02-2012, 01:04 AM
Gustavus Re: Help with Transposing Code 11-02-2012, 03:34 PM
rylo Re: Help with Transposing Code 11-04-2012, 07:20 PM
  1. #1
    Registered User
    Join Date
    10-31-2012
    Location
    West Virginia
    MS-Off Ver
    Excel 2010
    Posts
    3

    Help with Transposing Code

    Hello all,

    I have been assigned to transpose and reformat loads and loads of data. I am familiar with excel and computer programming (mostly matlab), but I have never written code for excel. I have begun the assignment using the transpose function and going line by line.

    I have attached the portion of the data that I have already processed. In the first worksheet, the data is formatted as it is given to me. In the second worksheet is the format to which I must convert the data. Essentially, all the data for 1 subject must be placed in 1 row. The especially tedious part (transposing) has been highlighted in red. There are varying amounts of data that must be transposed, but there is consistently 1 blank row between subjects.

    If anyone has ideas for helping me with this assignment it would be very much appreciated.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Help with Transposing Code

    Hi

    Try this

    Sub aaa()
      Dim OutSh As Worksheet
      Set OutSh = Sheets("Sheet1")
      
      OutSh.Range("A1:Z1").Value = Array("ID", "visit", "study", "MET", "TRAIN", "AGE", "Height ", "Weight", "%BF", "Race", "Meds", "DR", "BSA", "BMI", "***", "MWL", "duration of ex", "Date of Test", "PWV", "cf", "MAP", "cr", "MAP", "v02_0", "VO2_25", "VO2_50")
      OutSh.Range("AA1:AZ1").Value = Array("VO2_75", "VO2_100", "VO2_125", "VO2_150", "VO2_175", "VO2_200", "VO2_225", "vo2max", "VCo2_0", "VCo2_25W", "VCo2_50W", "VCo2_75W", "VCo2_100W", "VCo2_125W", "VCo2_150W", "VCo2_175W", "VCo2_200W", "VCo2_225W", "VCO2max", "RER_0", "RER_25", "RER_50", "RER_75", "RER_100", "RER_125", "RER_150")
      OutSh.Range("BA1:BZ1").Value = Array("RER_175", "RER_200", "RER_225", "RER_max", "VE_0", "VE_25", "VE_50", "VE_75", "VE_100", "VE_125", "VE_150", "VE_175", "VE_200", "VE_225", "VE_max", "VT_0", "VT_25", "VT_50", "VT_75", "VT_100", "VT_125", "VT_150", "VT_175", "VT_200", "VT_225", "VT_max")
      OutSh.Range("CA1:CZ1").Value = Array("BORG_0", "BORG_25", "BORG_50", "BORG_75", "BORG_100", "BORG_125", "BORG_150", "BORG_175", "BORG_200", "BORG_225", "BORG_max", "SBP_0", "SBP_25", "SBP_50", "SBP_75", "SBP_100", "SBP_125", "SBP_150", "SBP_175", "SBP_200", "SBP_225", "SBP_max", "DBP_0", "DBP_25", "DBP_50", "DBP_75")
      OutSh.Range("DA1:DR1").Value = Array("DBP_100", "DBP_125", "DBP_150", "DBP_175", "DBP_200", "DBP_225", "DBP_max", "HR_0", "HR_25", "HR_50", "HR_75", "HR_100", "HR_125", "HR_150", "HR_175", "HR_200", "HR_225", "HR_max")
      
      For i = 3 To Cells(Rows.Count, "U").End(xlUp).Row
        If Len(Cells(i, "U")) > 0 Then
          outrow = OutSh.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
          rzrows = Cells(i + 1, 45).End(xlDown).Row - i
          OutSh.Cells(outrow, 1).Resize(1, 2).Value = Cells(i, 1).Resize(1, 2).Value
          OutSh.Cells(outrow, 3).Resize(1, 16).Value = Cells(i, 4).Resize(1, 16).Value
          OutSh.Cells(outrow, 20).Resize(1, 4).Value = Cells(i, 40).Resize(1, 4).Value
          OutSh.Cells(outrow, 24).Resize(1, rzrows).Value = WorksheetFunction.Transpose(Cells(i + 1, 45).Resize(rzrows, 1).Value)
          OutSh.Cells(outrow, 35).Resize(1, rzrows).Value = WorksheetFunction.Transpose(Cells(i + 1, 46).Resize(rzrows, 1).Value)
          OutSh.Cells(outrow, 46).Resize(1, rzrows).Value = WorksheetFunction.Transpose(Cells(i + 1, 47).Resize(rzrows, 1).Value)
          OutSh.Cells(outrow, 57).Resize(1, rzrows).Value = WorksheetFunction.Transpose(Cells(i + 1, 48).Resize(rzrows, 1).Value)
          OutSh.Cells(outrow, 68).Resize(1, rzrows).Value = WorksheetFunction.Transpose(Cells(i + 1, 49).Resize(rzrows, 1).Value)
          OutSh.Cells(outrow, 79).Resize(1, rzrows).Value = WorksheetFunction.Transpose(Cells(i + 1, 50).Resize(rzrows, 1).Value)
          OutSh.Cells(outrow, 90).Resize(1, rzrows).Value = WorksheetFunction.Transpose(Cells(i + 1, 51).Resize(rzrows, 1).Value)
          OutSh.Cells(outrow, 101).Resize(1, rzrows).Value = WorksheetFunction.Transpose(Cells(i + 1, 52).Resize(rzrows, 1).Value)
          OutSh.Cells(outrow, 112).Resize(1, rzrows).Value = WorksheetFunction.Transpose(Cells(i + 1, 53).Resize(rzrows, 1).Value)
        End If
      Next i
      
      OutSh.Activate
      lastrow = Cells(Rows.Count, 1).End(xlUp).Row
      formarr = Array("AH", "AS", "BD", "BO", "BZ", "CK", "CV", "DG", "DR")
      For i = LBound(formarr) To UBound(formarr)
          Range(formarr(i) & 2).Formula = "=MAX(rc[-10]:rc[-1])"
          Range(formarr(i) & 2).AutoFill Destination:=Range(formarr(i) & "2:" & formarr(i) & lastrow)
      Next i  
      
    End Sub
    rylo
    Last edited by rylo; 10-31-2012 at 09:27 PM. Reason: Version 2

  3. #3
    Registered User
    Join Date
    10-31-2012
    Location
    West Virginia
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Help with Transposing Code

    Thanks a ton man... I ran the code and it appears to have worked other than that it skipped 2 rows, I am trying to figure out why it skipped them, but haven't had much time to investigate it. Thanks again rylo, I may have some questions about how the code works after I get a chance to look at it some more

  4. #4
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Help with Transposing Code

    Hi

    did it skip them in the example file or in something else?

    rylo

  5. #5
    Registered User
    Join Date
    10-31-2012
    Location
    West Virginia
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Help with Transposing Code

    the skips occurred in an extended version of the same file... I would post the entire file, but I didn't record the data so I don't feel it is my place to put it on the internet... It appears to me that these skipped rows occurred due to missing data in the U column referenced in the code. Should be an easy fix

  6. #6
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Help with Transposing Code

    Hi

    IF there is likely to be data missing from column U, then which column for the "first appearance" type rows will always be completed?

    rylo

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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