AutoFill to Last row of Data

JeezisPope

New Member
Joined
Sep 7, 2022
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hey guys,
I'm new at programming with vba and I have this annoying problem where I want to Autofill to Last row of data, but i don't know how. I have to select from A4 to K4 and then Autofill it, but the amount of data is indefinite...
photo.png


I have this code so far, so if anyone can help pls, would be great... I do a little researching, and i found some ways to do it, but i couldn't understand... Help pls

Sub lastrow()

Range("A4:K4").Select
Selection.AutoFill Destination:=Range("A4:K" & Range(Rows.Count, "K").End(xlUp).Row)
End Sub
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Welcome to the Board!

You want to go down to the last row of data found in column L, so try:
Rich (BB code):
Sub lastrow()
    Range("A4:K4").AutoFill Destination:=Range("A4:K" & Range(Rows.Count, "L").End(xlUp).Row)
End Sub
 
Upvote 0
Welcome to the Board!

You want to go down to the last row of data found in column L, so try:
Rich (BB code):
Sub lastrow()
    Range("A4:K4").AutoFill Destination:=Range("A4:K" & Range(Rows.Count, "L").End(xlUp).Row)
End Sub
Hey, I think the code is good, but i don't know why it appears the runtime error 1004,
I tried to set the range as a variable, but it didn't work either. I don't know what's happening there, can u help me pls?
 
Upvote 0
Whoops, I copied your formula and missed an error you had in there.
It should be:
Rich (BB code):
    Range("A4:K4").AutoFill Destination:=Range("A4:K" & Cells(Rows.Count, "L").End(xlUp).Row)
not
Rich (BB code):
    Range("A4:K4").AutoFill Destination:=Range("A4:K" & Range(Rows.Count, "L").End(xlUp).Row)

So it should be:
VBA Code:
Sub lastrow()
    Range("A4:K4").AutoFill Destination:=Range("A4:K" & Cells(Rows.Count, "L").End(xlUp).Row)
End Sub
 
Upvote 0
Solution
Whoops, I copied your formula and missed an error you had in there.
It should be:
Rich (BB code):
    Range("A4:K4").AutoFill Destination:=Range("A4:K" & Cells(Rows.Count, "L").End(xlUp).Row)
not
Rich (BB code):
    Range("A4:K4").AutoFill Destination:=Range("A4:K" & Range(Rows.Count, "L").End(xlUp).Row)

So it should be:
VBA Code:
Sub lastrow()
    Range("A4:K4").AutoFill Destination:=Range("A4:K" & Cells(Rows.Count, "L").End(xlUp).Row)
End Sub
thanks!! it worked perfectly
 
Upvote 0
You are welcome.

I hope it makes sense.
If not, feel free to ask any questions.
 
Upvote 0

Forum statistics

Threads
1,215,045
Messages
6,122,830
Members
449,096
Latest member
Erald

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