Hi
I've one workbook that contains 31 sheets (1 for each day). I want macro to open source workbook and loop through each sheet and copy range H15:H28 and paste it in active (Target) workbook from B4. I've code that does the job. But I want some change. After pasting in 16 columns i.e. up to Q4, next pasting should start from B20.
Here is the code
Sub UtilityConsumption()
Dim ws As Worksheet
Dim TargetWb As Workbook
Dim SourceWb As Workbook
Range("B4").Activate
Application.ScreenUpdating = False
Set TargetWb = ActiveWorkbook
Set SourceWb = Workbooks.Open("X:\XXX\XXX.xlsm")
SourceWb.Worksheets("1 April 2019 ").Activate
For Each ws In Sheets
Range("H15:H28").Copy
TargetWb.Activate
ActiveCell.Offset(0, 0).Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats
ActiveCell.Offset(0, 1).Range("A1").Select
SourceWb.Activate
ActiveSheet.Previous.Select
On Error GoTo exiterr
Next ws
exiterr:
Application.CutCopyMode = False
SourceWb.Close
End Sub
I've one workbook that contains 31 sheets (1 for each day). I want macro to open source workbook and loop through each sheet and copy range H15:H28 and paste it in active (Target) workbook from B4. I've code that does the job. But I want some change. After pasting in 16 columns i.e. up to Q4, next pasting should start from B20.
Here is the code
Sub UtilityConsumption()
Dim ws As Worksheet
Dim TargetWb As Workbook
Dim SourceWb As Workbook
Range("B4").Activate
Application.ScreenUpdating = False
Set TargetWb = ActiveWorkbook
Set SourceWb = Workbooks.Open("X:\XXX\XXX.xlsm")
SourceWb.Worksheets("1 April 2019 ").Activate
For Each ws In Sheets
Range("H15:H28").Copy
TargetWb.Activate
ActiveCell.Offset(0, 0).Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats
ActiveCell.Offset(0, 1).Range("A1").Select
SourceWb.Activate
ActiveSheet.Previous.Select
On Error GoTo exiterr
Next ws
exiterr:
Application.CutCopyMode = False
SourceWb.Close
End Sub