Autofill down from a variable cell

BillyH

New Member
Joined
May 3, 2016
Messages
2
I'd like to create a template that can copy and paste data, while autofilling data next to it.



The data I have would be pasted in random amounts, so I have no set Range to reference. I have part of some code that lets me paste down to the last row of another column, but the code I have won't let me also select a variable Range to autofill down to the other column.

I'd like to select the last cell in C, then have it autofill to the lastrow in D (Which is already set up in the first part of the Macro.



Here's the current code for one part of my macro:




Dim lastrow As Long

lastrow = Worksheets("Sheet1").Range("D4").End(xlDown).Row
With Worksheets("Sheet1").Range("C4").Select
Selection.End (xlDown)
.AutoFill Destination:=Range("C4:C" & lastrow&)
End With





But instead of Range(C4) I'd like it to be a variable Range - sometimes it may be at C56, then the next it could be at C20.

Something such as - Range ("C" & Cells(Rows.Count, "C").End(xlUp))

I've read through a few posts on autofilling, but none have provided a formula that changes where the autofill is last selected from
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
So you want to copy from the last used row in "C" down to the equivalent last used row in "D" ???
 
Upvote 0
So you want to copy from the last used row in "C" down to the equivalent last used row in "D" ???

Yes. That about sums it up.

To give more background, I have another part of the code that is copying and pasting some values down in "D", then I would need "C" to be autofilled only as far as D was copied. This happens multiples times. Copy a bunch of values in "D" drop down formula in "C" -repeat.
 
Upvote 0
maybe this
Code:
Sub MM1()
Dim lr As Long, lr2 As Long
lr = Range("D4").End(xlDown).Row
lr2 = Range("c4").End(xlDown).Row
Range("C" & lr2).AutoFill Destination:=Range("C" & lr2 & ":C" & lr)
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,971
Members
452,371
Latest member
Frana

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