Copy Columns from one Workbook into another

Sherifa

New Member
Joined
Oct 23, 2017
Messages
45
Copy Columns from one Workbook into another, looping through sheets 6 to the last in the worksheet.

Error message
Compile Error:
Duplicate declaration in current scope

Sub CopyaColumnToWorkbook()


Dim SourceWkb As Excel.Workbook
Dim TargetWkb As Excel.Workbook




Set SourceWkb = Workbooks.Open("I:\Documents\Transactional FX\Michael Kyte Projects\VBA.xlsm")
Set TargetWkb = Workbooks.Open("I:\Documents\Transactional FX\Michael Kyte Projects\VBA1.xlsm")


Dim SourceColumn As Range
Dim TargetColumn As Range


Set SourceColumn = SourceWkb.Worksheets(s).Columns("e:g")
Set TargetColumn = TargetWkb.Worksheets(t).Columns("e:g")


Dim ws_sourcecount As Integer
Dim ws_targetcount As Integer





ws_sourcecount = SourceWkb.Worksheets.Count
ws_targetcount = TargetWkb.Worksheets.Count

Dim s As Integer
Dim t As Integer

'Begin loop
For s = 7 To ws_sourcecount
For t = 7 To ws_targetcount


SourceWkb.Worksheets(s).Select 'just select the sheet
'Copy from first workbook

SourceColumn.Copy


TargetWkb.Worksheets(t).Select 'just select the sheet
'Paste formulas into second workbook
'Offset Paste (Offset 3 cell to the right)

TargetColumn.Offset(0, 3).PasteSpecial Paste:=xlPasteFormulas

Next s
Next t


End Sub
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

Forum statistics

Threads
1,215,332
Messages
6,124,314
Members
449,153
Latest member
JazzSingerNL

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