Code not looping through multiple sheets as intended - VBA

jwb1012

Board Regular
Joined
Oct 17, 2016
Messages
167
Hello, I am using the following code to copy/paste a range from one worksheet to multiple sheets. But, my code is only pasting the range onto the sheet that is currently open. Any thoughts on how to get it to copy paste to all sheets that begin with "Labor BOE"?

Here is the line in my code that appears to be not working/ignored:

For Each sh In ActiveWorkbook.Sheets
If Left(sh.Name, 9) = "Labor BOE" Then



Full Code:
Sub CopyPaste_Range()
Dim sh As Worksheet

'Copy Range
Sheets("Template - Tasks").Range("A20:L28").Copy

'Paste to active sheet
For Each sh In ActiveWorkbook.Sheets
If Left(sh.Name, 9) = "Labor BOE" Then

lastRow = ActiveSheet.Cells(Rows.Count, "L").End(xlUp).Row + 1
Range("A" & lastRow).Select

ActiveSheet.Paste
End If

Next sh
Application.DisplayAlerts = True
On Error GoTo 0
End Sub
 

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