Autofill Column to Last Row of Data - VBA

mihand

New Member
Joined
Jun 2, 2020
Messages
7
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hello,
I am trying to figure out the code needed to autofill a column to the last row of data. The macro will be used on a standard report that will have various rows of data. Below is what I currently have. I am looking to autofill columns X through AJ and stop at the last row of data. When I created the macro, it had 19280 rows. I can edit it each month or simply use a greater number and filter out the blanks in the pivot table, but I rather have the code produce a report that people do not need to edit or do another step.

Range("X2:AJ2").Select
Selection.AutoFill Destination:=Range("X2:AJ19280")
Range("X2:AJ19280").Select
Range("X2").Select
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Try testing the code below on a copy of your worksheet.

VBA Code:
Range("X2:AJ2").AutoFill Range("X2:AJ" & Range("U" & Rows.Count).End(xlUp).Row)
Range("X2").Select

Please note that the code needs amending if the sheet is not going to be the ActiveSheet.
 
Upvote 0
Try testing the code below on a copy of your worksheet.

VBA Code:
Range("X2:AJ2").AutoFill Range("X2:AJ" & Range("U" & Rows.Count).End(xlUp).Row)
Range("X2").Select

Please note that the code needs amending if the sheet is not going to be the ActiveSheet.
Thanks. That seemed to have worked.
 
Upvote 0
Happy it helped and welcome to the board :)
 
Upvote 0

Forum statistics

Threads
1,214,587
Messages
6,120,405
Members
448,958
Latest member
Hat4Life

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