Stack columns from a matrix

T

Tom

I need a macro to take a 6 column, 6 row matrix, for instance, and stack the
columns 2 at a time on top of each other on another sheet in the spreadsheet.
If the columns were A-F, they would end up stacked
AB
CD
EF

Actually the matrix is about 52 columns by 419 rows with many blanks.

Thanks in advance for the help.
 
J

joel

I used PasteSpecial to skip the blanks. sometimes it doesn't work lik
you would expect if you are copying multiple columns. try this macr
first and see if you get good results. change the 10 below to th
number of columns you are using. If your last column of data is in Ro
1 you can get the last column adding this to the code

LastCol = .cells(1,columns.Count).end(xltoleft).column

Then replace the 10 with LastCol



Sub Copycolumns()


With Sheets("Sheet1")
For ColCount = 1 To 10 Step 2
LastRow = .Cells(Rows.Count, ColCount).End(xlUp).Row
Set CopyRange = .Range(.Cells(1, LastRow), _
.Cells(LastRow, ColCount + 1))
CopyRange.Copy

With Sheets("sheet2")
LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
NewRow = LastRow + 1
.Range("A" & NewRow).PasteSpecial _
Paste:=xlPasteValues, _
SkipBlanks:=True
End With
Next ColCount
End With


End Su
 

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