Running Macro on multiple worksheets using prefix

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
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Not sure what your question or problem is, but looking at your code, it is only selecting a piece, perhaps as small as a single cell in col L to copy, while your post states you want to copy a dynamic range across cols A to L. Is that your issue? If yes, will the data you want to copy always start in the same cell in col A? If so, which cell in col A is that?

If that's not the issue, can you provide some more detail about what you need help with?
 
Upvote 0

Forum statistics

Threads
1,223,248
Messages
6,171,021
Members
452,374
Latest member
keccles

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