• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 367
  • Last Modified:

Automate Transpose One Column, Copy Another Column

Please see the attached file.  On Sheet 1, Column A contains trend codes.  Columns B potentially all the way through Column X contain codes that are to be mapped to Column A.

The challenge I have is to take Columns B through X, copy and transpose them onto Sheet 2 so that they are all in one column.  Then I need to copy Column A and paste it in the second column on Sheet 2 in each cell next to its corresponding code from Sheet 1.

I could do this all manually, but I am hoping I can automate it with code and there are 1118 rows which could take many hours.  I am very familiar with vba for Access, but I have never done any coding for Excel.
  • 3
1 Solution

Here's code that should do just that (at least, if I understood what you needed).

Sub yeaaah()
Dim rgCell As Range, shtOrg As Worksheet, shtDest As Worksheet
Dim lRowDest As Long
'turn off updates to speed up code execution
With Application
    .ScreenUpdating = False
    .EnableEvents = False
    .Calculation = xlCalculationManual
    .DisplayAlerts = False
End With

Set shtOrg = ActiveSheet
Set shtDest = Sheets.Add

For Each rgCell In shtOrg.Cells(2, 2).Resize(shtOrg.UsedRange.Rows.Count - 1, shtOrg.UsedRange.Columns.Count - 1).SpecialCells(xlCellTypeConstants)
    shtDest.Cells(lRowDest + 1, 1) = rgCell
    shtDest.Cells(lRowDest + 1, 2) = shtOrg.Cells(rgCell.Row, 1)
    lRowDest = lRowDest + 1
Next rgCell

With Application
    .ScreenUpdating = True
    .EnableEvents = True
    .Calculation = xlCalculationAutomatic
    .DisplayAlerts = True
End With

End Sub

Open in new window

Harry LeeCommented:

Can you post the ending result for the sample file you have uploaded?

Have no idea what are you trying to do exactly.
SDKCompanyAuthor Commented:
I have uploaded the Excel file with a tab that has an example of what I am looking to get for the final product.  I have used the data from the first 8 rows of Sheet1 for the example.


I have not had a chance to try your code yet, but I will post the results as soon as I can.


SDKCompanyAuthor Commented:

Your code works great.  I need to do a little more verification, but it appears that it does exactly what I need.  Thank you!
SDKCompanyAuthor Commented:
Worked perfectly!  Thank you!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now