paste transpose

S

Sheela

I have a workbook with multiple pages. Each page has data in only first column.
I like to copy the data from the first column and paste transpose into first
2 rows.
and then delete the first column.
I have the following code, but it is not working properly.
1) it is not looping through the excel pages.
2. It is deleting the entire data ( not just the first column) except the
first cell.


Can you tell me where the code is wrong and also can you suggest a more
efficient way to do this.
thanks in advance.
###
Public Sub Paste_Transpose()
Dim ws As Worksheet

Dim Lastrow As Long
For Each ws In ActiveWorkbook.Worksheets
Lastrow = ActiveCell.SpecialCells(xlCellTypeLastCell).Row


Range(Cells(1, 1), Cells(Lastrow, 1)).Copy
Range(Cells(1, 1), Cells(2, Lastrow + 1)).PasteSpecial Paste:=xlPasteAll,
Transpose:=True
Range(Cells(1, 1), Cells(Lastrow, 1)).Delete
Next ws



End Sub
 
O

Otto Moehrbach

Sheela
Your code works on only the active sheet. The For loop loops through
all the sheets in the workbook, but your code says to work on only the
active sheet. So it does. I modified your code so that all the operations
are done to the ws sheet. HTH Otto
Public Sub Paste_Transpose()
Dim ws As Worksheet
Dim Lastrow As Long
For Each ws In ActiveWorkbook.Worksheets
With ws
Lastrow = .Range("A" & Rows.Count).End(xlUp).Row
.Range(.Cells(1, 1), .Cells(Lastrow, 1)).Copy
.Range(.Cells(1, 1), .Cells(2, Lastrow + 1)).PasteSpecial
Paste:=xlPasteAll, Transpose:=True
.Range(.Cells(1, 1), .Cells(Lastrow, 1)).ClearContents
End With
Next ws
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top