VBA Code to import Multiple column fron one sheet to another

Smoulder

New Member
Joined
Jul 28, 2017
Messages
1
Hi,
I am trying to import a few columns from one excel spreadsheet to another. Below is the code that I have found on a forum which is working fine. the only problem I am facing is it is importing only one column.can someone please guide how I can edit the code so that I can importing multiple columns

Importing single Column
Sub CopyColumnToWorkbook()
Dim sourceColumn As Range, targetColumn As Range

Set sourceColumn = Workbooks("Source.xlsm").Worksheets("2017"). Columns(“A”)
Set targetColumn = Workbooks("Target.xlsm").Worksheets("Field WH Projections").Columns(“A”)

sourceColumn.Copy Destination:=targetColumn
End

Thanks
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
are you looking to copy a fixed number of columns or the last column with data?
-if its fixed
--just change your last part of your first declarations from .Columns("A") to
Code:
.Columns("A:Z")

if its variable and need to take the last column with data

Code:
Set sourceColumn = workbooks("Source.xlsm").Worksheets("2017").Range("A1", Range("A" & Range("A" & Rows.Count).End(xlUp).Row).End(xlToRight))

I believe that should work, but let me know if you have issues
 
Upvote 0

Forum statistics

Threads
1,215,375
Messages
6,124,576
Members
449,173
Latest member
Kon123

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