Hello all,
I have a sheet with 50 columns. I need to copy 4 of them and paste them on a newly created sheet, but in a different order. The new order should be: C-B-D-E
This is my code so far. The copying works OK, but the result is that all data stays in the original order B-C-D-E.
Thanks for any help!
I have a sheet with 50 columns. I need to copy 4 of them and paste them on a newly created sheet, but in a different order. The new order should be: C-B-D-E
This is my code so far. The copying works OK, but the result is that all data stays in the original order B-C-D-E.
Thanks for any help!
VBA Code:
Sub copy()
Dim ws As Worksheet
Dim lastRow, lastCol As Long
Set ws = Sheets("Sheet1")
ws.Select
lastRow = Range("A:A").Find("*", , , , xlByRows, xlPrevious, , , False).Row
lastCol = Range("1:1").Find("*", , , , xlByColumns, xlPrevious, , , False).Column
Set rng2copy = Application.Union(Range("C1:C" & lastRow), Range("B1:B" & lastRow), Range("D1:D" & lastRow), Range("E1:E" & lastRow))
rng2copy.Copy
Sheets.Add(After:=Sheets(Sheets.Count)).Name = "Selection"
ActiveSheet.Paste Cells(1, 1)
Application.CutCopyMode = False
End Sub