copy columns in different sequence to new sheet

opislak

New Member
Joined
Feb 28, 2017
Messages
45
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
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,468
Office Version
  1. 365
Platform
  1. Windows
Glad we could help & thanks for the feedback.
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Watch MrExcel Video

Forum statistics

Threads
1,129,380
Messages
5,635,918
Members
416,887
Latest member
SheriE

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
Top