copy columns in different sequence to new sheet

opislak

Board Regular
Joined
Feb 28, 2017
Messages
68
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!
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
 
Glad we could help & thanks for the feedback.
 
Upvote 0

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

Forum statistics

Threads
1,212,927
Messages
6,110,696
Members
448,293
Latest member
jin kazuya

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top