Macro to autofill to the last row.

I created a macro to autofill to the last row but it does not work correctly. I looked up a few other macros and they did not work for me either. Can someone take a look at this macro I made and see what changes I need, to make it go to the last row. Thanks!
Sub fill()

Selection.Autofill Destination:=Range("N2:R16586")
End Sub
LVL 19
Edward PamiasTeam Lead RRS DeskAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Saurabh Singh TeotiaCommented:
Use this code...

Sub fill()
Dim lrow As Long

lrow = Cells.Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Selection.AutoFill Destination:=Range("N2:R" & lrow)
Range("N2:R" & lrow).Select
End Sub

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Edward PamiasTeam Lead RRS DeskAuthor Commented:
This worked perfectly! Thank you!
Rob HensonFinance AnalystCommented:
Assuming you have data in column M all the way down, you don't need a macro.

Select cells N2:R2 and then hover the cursor over the bottom right corner of R2, the cursor will change to a bold + symbol.  Double click and it will fill down columns N to R as far as there is data in column M.

Rob H
Active Protection takes the fight to cryptojacking

While there were several headline-grabbing ransomware attacks during in 2017, another big threat started appearing at the same time that didn’t get the same coverage – illicit cryptomining.

Edward PamiasTeam Lead RRS DeskAuthor Commented:
Thanks Rob! I was being lazy and wanted a quick way of doing it. Look out for my next question. Coming soon! You have been a big help.
Rob HensonFinance AnalystCommented:
Highlight and double-click can't be much slower. Also advantage of using non-VBA procedures is that they can be undone.

When you run a macro, it clears the Undo history.
Edward PamiasTeam Lead RRS DeskAuthor Commented:
Thanks Rob! I will remember that for the future. My other question is out there and I know you are going to say didn't I ask this already. The answer is no.... this is a bit different.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.