Array to copy columns

  • Thread starter FIRSTROUNDKO via OfficeKB.com
  • Start date
F

FIRSTROUNDKO via OfficeKB.com

Hi,

I would like to copy from Sheet1 Columns B ,A, C in that order

to

Sheet 2 Columns A , B, C

can this be done by array

i.e myarray(B,A,C)

Thanks in advance
 
F

FIRSTROUNDKO via OfficeKB.com

I found this code but the order of columns remains A,B,C


myarray = "B:B,A:A,C:C"
Worksheets("Sheet1").Range(myarray).Copy Worksheets("Sheet2").Range("A1")
 
F

FIRSTROUNDKO via OfficeKB.com

here is the answer

Sub assignArray()
Dim Arr(3)

Dim X As Long

Arr(1) = "B:B"
Arr(2) = "A:A"
Arr(3) = "C:C"

For X = 1 To 3
' Columns("K:K").Select

Worksheets("Sheet1").Columns(Arr(X)).Copy Worksheets
("Sheet2").Cells(1, X)

Next X

End Sub
I found this code but the order of columns remains A,B,C

myarray = "B:B,A:A,C:C"
Worksheets("Sheet1").Range(myarray).Copy Worksheets("Sheet2").Range("A1")
[quoted text clipped - 9 lines]
Thanks in advance
 
D

Don Guillett

Another way
Sub CopycolumnsCustom()
With Sheets("Sheet14")
Sheets("sheet9").Columns("A:C").Copy .Range("a1")
Application.CutCopyMode = False
.Columns("B").Cut
.Columns("A").Insert , Shift:=xlToRight
End With
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(e-mail address removed)
FIRSTROUNDKO via OfficeKB.com said:
here is the answer

Sub assignArray()
Dim Arr(3)

Dim X As Long

Arr(1) = "B:B"
Arr(2) = "A:A"
Arr(3) = "C:C"

For X = 1 To 3
' Columns("K:K").Select

Worksheets("Sheet1").Columns(Arr(X)).Copy Worksheets
("Sheet2").Cells(1, X)

Next X

End Sub
I found this code but the order of columns remains A,B,C

myarray = "B:B,A:A,C:C"
Worksheets("Sheet1").Range(myarray).Copy Worksheets("Sheet2").Range("A1")
[quoted text clipped - 9 lines]
Thanks in advance
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top