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:

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
One way:
Code:
    Dim lastRow As Long
    lastRow = Range("G1").End(xlDown).Row
    Range("G1:L" & lastRow).Select
 
Upvote 0
Another way to try (if I haven't made any typos on my phone)


Code:
Range("G1:M1").Autofill Range("G1:M" & Range("G" & Rows.Count).End(xlUp).Row)
 
Upvote 0
@Joe4
That seems to just select that range but not autofill anything? Am I missing something there?

@MARK858
Issue with this (other than me having headers) is that I have a second set of data 4 rows below this selected set which is why I am using .End(xlDown)
I am going to do some trial and error to see if I can get it to work unless you beat me to it.
 
Upvote 0
I was just showing you how to get your range, not the Autofill piece.
I think we need more information for that.
If you are using column G to determine that last row, then I don't think you are autofilling that column (as it is already populated).
So then are you just autofilling columns H through L?
Does row 1 have formulas in all those columns to be autofilled down?

If my assumptions above are correct, then just use:
Code:
    Dim lastRow As Long
    lastRow = Range("G1").End(xlDown).Row
    Range("H1:L1").AutoFill Range("H1:L" & lastRow)
or just
Code:
    Range("H1:L1").AutoFill Range("H1:L" &  Range("G1").End(xlDown).Row)
 
Last edited:
Upvote 0
I think all that I need is for it to match the number of rows in column F.
Column G to L all have less rows than A thru F.
H, I, K, and L have formulas that need to be autofilled but G and J are filled with other macros (after this sub runs).
Row 1 is headers so this would begin at row 2.
 
Last edited:
Upvote 0
Then try:
Code:
    Range("H2:L2").AutoFill Range("H2:L" &  Range("F1").End(xlDown).Row)
 
Upvote 0
And since I have a second set of data beneath this set some functions like Mark's wont work. Sorry I didn't specify that in the OP.

I figured I could just modify the autofill code to fit the second set as well because when doing it not in vba all you do is click the cross and it fills correctly.
 
Upvote 0
@MARK858
Issue with this (other than me having headers) is that I have a second set of data 4 rows below this selected set which is why I am using .End(xlDown)
I am going to do some trial and error to see if I can get it to work unless you beat me to it.

As a guess...
Code:
Range("G1:L1").Autofill Range("G1:L1").Resize(5, 1)

Edit: Sorry Joe4 I missed post #7 :(
 
Last edited:
Upvote 0
And since I have a second set of data beneath this set some functions like Mark's wont work. Sorry I didn't specify that in the OP.
As long as you have blank rows between your data sets, I believe the code I posted up in post #7 should do what you want.
 
Upvote 0

Forum statistics

Threads
1,223,884
Messages
6,175,175
Members
452,615
Latest member
bogeys2birdies

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