![]() |
Stack columns from a matrix
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. -- Tom |
Stack columns from a matrix
I used PasteSpecial to skip the blanks. sometimes it doesn't work like you would expect if you are copying multiple columns. try this macro first and see if you get good results. change the 10 below to the number of columns you are using. If your last column of data is in Row 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 Sub -- joel ------------------------------------------------------------------------ joel's Profile: 229 View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=172404 Microsoft Office Help |
All times are GMT +1. The time now is 05:44 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com