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
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