alwaysdanish
New Member
- Joined
- Aug 9, 2018
- Messages
- 1
I am working on a worksheet with multiple tabs although I need to copy data from worksheets that start with only "2018 and 2017".
From these sheets I wanted to copy range - using variables (say I wanted to copy a range between column A to L but the range should be dynamic )
and then paste the data in summary tab-
Below is the codes i have written so far, although i am not getting any error
Sub NETWORK()
Dim sheet As Worksheet
Dim a As String
Dim B As String
a = Range("L1").End(xlDown).Address
B = Range("L1048576").End(xlUp).Address
Sheets("Summary").Activate
For Each sheet In Worksheets
If (Left(sheet.Name, 4) = "2018") Or (Left(sheet.Name, 4) = "2019") Then
sheet.Select
sheet.Range(a, B).Select
Range(Selection, Selection.End(xlToLeft)).Select
Selection.Copy
Worksheets("Summary").Select
Worksheets("Summary").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial (xlPasteValues)
End If
Next sheet
End Sub
From these sheets I wanted to copy range - using variables (say I wanted to copy a range between column A to L but the range should be dynamic )
and then paste the data in summary tab-
Below is the codes i have written so far, although i am not getting any error
Sub NETWORK()
Dim sheet As Worksheet
Dim a As String
Dim B As String
a = Range("L1").End(xlDown).Address
B = Range("L1048576").End(xlUp).Address
Sheets("Summary").Activate
For Each sheet In Worksheets
If (Left(sheet.Name, 4) = "2018") Or (Left(sheet.Name, 4) = "2019") Then
sheet.Select
sheet.Range(a, B).Select
Range(Selection, Selection.End(xlToLeft)).Select
Selection.Copy
Worksheets("Summary").Select
Worksheets("Summary").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial (xlPasteValues)
End If
Next sheet
End Sub