i have a sheet that has many columns and i want to sort them i attached an example sheet 2 is the sheet that must be changed in to sheet one
i have a sheet that has many columns and i want to sort them i attached an example sheet 2 is the sheet that must be changed in to sheet one
Last edited by CORAL; 04-09-2014 at 02:20 PM.
Try thisCode:Sub ColumnizeExcelFox() Dim lngLast As Long Const clngCol As Long = 2 Worksheets("Sheet2").UsedRange.Clear With Worksheets("Sheet1") lngLast = .Cells(.Rows.Count, 1).End(xlUp).Row Do Until lngLast <= 1 .Range(.Cells(lngLast, 1).End(xlUp)(0), .Cells(lngLast, clngCol)).Copy Worksheets("Sheet2").Cells(1) lngLast = .Cells(lngLast, 1).End(xlUp).Row - 2 If lngLast > 0 Then Worksheets("Sheet2").Cells(1).Resize(, clngCol).EntireColumn.Insert End If Loop End With End Sub
A dream is not something you see when you are asleep, but something you strive for when you are awake.
It's usually a bad idea to say that something can't be done.
The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve
Join us at Facebook
Please use puctuation marks in your posts.
Could you please clarify that, snb. Not sure what you were referring to.
A dream is not something you see when you are asleep, but something you strive for when you are awake.
It's usually a bad idea to say that something can't be done.
The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve
Join us at Facebook
hi Mr
your code change sheet 1 in to sheet 2 but i want the code for changing sheet 2 into sheet 1
so i think(not sure) the subject should be changed in to:
"VBA To Split A Group Or Set Of Data In columns In To row"
Last edited by CORAL; 04-11-2014 at 08:09 AM.
Acts on the active sheet as the source sheet, creates a new sheet.Code:Sub blah() Set SceSht = ActiveSheet Set NewSht = Sheets.Add(after:=Sheets(Sheets.Count)) Set Destn = NewSht.Cells(1, 1) Application.Goto Destn With SceSht lc = .Cells(1, .Columns.Count).End(xlToLeft).Column For i = 1 To lc Step 2 Set RngToCopy = Intersect(.UsedRange, .Cells(1, i).Resize(, 2).EntireColumn) RngToCopy.Copy Destn Set Destn = Destn.Offset(RngToCopy.Rows.Count) Application.Goto Destn Next i End With NewSht.Columns("A:B").AutoFit End Sub
The values seem to be be awry on your sheet 1.
I've just realised that I left 2 debug lines in which don't need to be there; they are the 2 lines:
Application.Goto Destn
Delete them.
Bookmarks