VBA Only Updating Active Sheet But Is Coded To Loop

Worker8ee

New Member
Joined
Aug 8, 2018
Messages
28
Hello – I am trying to run this loop where I autofill Column M from M5 all the way down to the last row (last row is based on Column E). It performs just fine for the sheet I run it on but then it just stops. No error message or anything but it fails to continue the process throughout the sheets. Would anyone be able to shine any light on this issue based on the following VBA I am using? Any help would be greatly appreciated:

 
Dim sht As Worksheet
Dim LastR As Long
For Each sht In ThisWorkbook.Worksheets
With ActiveSheet
LastR = Range("E" & Rows.Count).End(xlUp).Row
.Range("M5").AutoFill Destination:=Range("M5:M" & LastR)
End With
Next sht

 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
remove the reference to Active Sheet and preface all ranges with sht.
 
Upvote 0
i think you want this.

Code:
Dim sht As Worksheet
Dim LastR As Long
For Each sht In ThisWorkbook.Worksheets
With sht
LastR = .Range("E" & Rows.Count).End(xlUp).Row
.Range("M5").AutoFill Destination:=.Range("M5:M" & LastR)
End With
Next sht
 
Upvote 0
Many thanks to both of you alansidman and rpaulson. I am embarrassed I didn't catch that but thanks for taking the time out of your day to reply!
 
Upvote 0

Forum statistics

Threads
1,223,905
Messages
6,175,297
Members
452,633
Latest member
DougMo

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