VBA to drag formula to last row across multiple sheets within workbook

aaw23

New Member
Joined
Mar 25, 2021
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
I am using the below code to drag the contents of the range selected down to the last row populated (as dictated by value in Col A). It works fine on the active sheet.

However it does not work when I want to perform across multiple sheets within the same workbook within the one function. Eg to perform the below function on every sheet within the workbook (about 80 sheets), where on each sheet the last row is variable.

Any assistance would be appreciated. Thanks

Dim Column_o_o As Long
Column_o_o = Range("A" & Rows.Count).End(xlUp).Row
Range("o22:q22").AutoFill Destination:=Range("o22:q" & Column_o_o), Type:=xlFillSeries
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,856
Office Version
  1. 365
Platform
  1. Windows
Hi & welcome to MrExcel.
How about
VBA Code:
Dim Ws As Worksheet
Dim Column_o_o As Long

For Each Ws In Worksheets
   Column_o_o = Ws.Range("A" & Rows.Count).End(xlUp).Row
   Ws.Range("o22:q22").AutoFill destination:=Ws.Range("o22:q" & Column_o_o), Type:=xlFillSeries
Next Ws
 

aaw23

New Member
Joined
Mar 25, 2021
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
Hi & welcome to MrExcel.
How about
VBA Code:
Dim Ws As Worksheet
Dim Column_o_o As Long

For Each Ws In Worksheets
   Column_o_o = Ws.Range("A" & Rows.Count).End(xlUp).Row
   Ws.Range("o22:q22").AutoFill destination:=Ws.Range("o22:q" & Column_o_o), Type:=xlFillSeries
Next Ws
Thanks very much for that, I just couldn't get it before. Really appreciate your assistance.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,856
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,130,119
Messages
5,640,219
Members
417,131
Latest member
Seanr19871

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
Top