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

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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