VBA Copy Multiple Columns

I am getting an error with the following line of code:
' WB.Sheets(PullItem).Range("A2:A" & NumItems, "D2:E" & NumItems, "M2:M" & NumItems, "I2:I" & NumItems, "G2:G" & NumItems, "N2:N" & NumItems, "L2:L" & NumItems, "J2:J" & NumItems).Copy

Open in new window

PullItem is a Constant for a Sheet name, and NumItems is a Variable for number of rows.
Error: Error nr: 450 Error Description: Wrong number of arguments or invalid property assignment.

I want to copy a number of non-adjacent columns from one sheet and and paste them into adjacent columns on another.
This works for one column, so I know variables etc are OK.
 WB.Sheets(PullItem).Range("Q2:R" & NumItems).Copy
  Range("B3").PasteSpecial (xlPasteValues)

Open in new window


Thanks.

John
LVL 6
johnb25Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rodney EndrigaData AnalystCommented:
I was able to use this code to pull the range you want:

WB.Sheets(PullItem).Range("A2:A" & NumItems & ",D2:E" & NumItems & ",M2:M" & NumItems & ",I2:I" & NumItems & ",G2:G" & NumItems & ",N2:N" & NumItems & ",L2:L" & NumItems & ",J2:J" & NumItems).Copy

Open in new window


Try it out and see if it works for you.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rodney EndrigaData AnalystCommented:
Something like this might work for you too:

Sub ee_CopyRange()
Dim rng As Range

Set rng = Range("A2:A" & NumItems & ",D2:E" & NumItems & ",M2:M" & NumItems & ",I2:I" & NumItems & ",G2:G" & NumItems & ",N2:N" & NumItems & ",L2:L" & NumItems & ",J2:J" & NumItems)
rng.Copy
End Sub

Open in new window

johnb25Author Commented:
Thanks Rodney, that worked.

Only thing is it is pasting back to my new sheet in the source column order, rather than the order in which I have them in the Range.Copy.
I think I will just repeat the copy/paste in the code; getting overly complicated for what I need.

John
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.