Autofill

dudewheresmyvba

New Member
Joined
Jul 6, 2017
Messages
29
Ok, so. I have my range selected through

Range("G1").Select
Selection.End(xlDown).Select
Range(ActiveCell, ActiveCell.Offset(0, 5)).Select

because it has changing number of rows.

I want to have those cells (G:L) autofilled but am having some difficulty finding the proper way to do it. If there is just 1 more line I need to add that would be super but if I need to use Dim and named ranges that would be fine too, but I don't know how to do that on my own yet.

Thanks
 
Last edited:
Yes Joe4 it works nicely for that one. If you could help, I am having trouble with doing the same for the second set.

Code:
Range("ActiveCell" & "ActiveCell.Offset(0, 5)").AutoFill Range("ActiveCell" & "ActiveCell.Offset(0, 5)" & Range("ActiveCell.Offset(0,-1)").End(xlDown).Row)

/edited

Which is laughably wrong.
 
Last edited:
Upvote 0

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Sometimes, I find it easier to break things up into multiple lines so it is easier to see what is going on. Shorter is not always better if you cannot follow what is going on, or won't remember what you did come next year when you are asked to support or change it.

So, I would use variables and do it like this:
Code:
    Dim lastRow As Long
    Dim nextRow As Long
    Dim lastRow2 As Long
    
'   Autofill set 1
    lastRow = Range("F1").End(xlDown).Row
    Range("H2:L2").AutoFill Range("H2:L" & lastRow)
    
'   Autofill set 2
    nextRow = Range("F" & lastRow).End(xlDown).Row
    lastRow2 = Range("F" & nextRow).End(xlDown).Row
    Range("G" & nextRow & ":L" & nextRow).AutoFill _
        Range("G" & nextRow & ":L" & lastRow2)
 
Upvote 0
Just add one to the next row calculation.
Code:
nextRow = Range("F" & lastRow).End(xlDown).Row + 1
 
Upvote 0

Forum statistics

Threads
1,224,819
Messages
6,181,153
Members
453,021
Latest member
Justyna P

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