Using a Named Field for Autofill [Solved]

Posts
3
Registration date
Tuesday June 11, 2019
Status
Member
Last seen
June 12, 2019
- - Latest reply: excel987
Posts
3
Registration date
Tuesday June 11, 2019
Status
Member
Last seen
June 12, 2019
- Jun 12, 2019 at 10:52 AM
I am performing an Autofill using a macro. Is there a way to enter the ranges using a "Named Field" in the macro without having to hardcode them in the macro? See my code below. I would like to avoid hard coding D23.

Range("D23").Select
Selection.AutoFill Destination:=Range("D23:D" & Range("C" & Rows.Count).End(xlUp).Row), Type:=xlFillSeries

Thanks!
See more 

1 reply

Best answer
Posts
13034
Registration date
Monday June 3, 2013
Status
Moderator
Last seen
October 11, 2019
1537
2
Thank you
You can initialize a variable, and use it. What is going to determine what that first value is? Take a look:


Firstrange="A1"

Selection.AutoFill Destination:=Range(Firstrange&":D" & Range("C" & Rows.Count).End(xlUp).Row), Type:=xlFillSeries

So as you see, we still have to initialize the variable with some usable range. Do you see the issue?

Say "Thank you" 2

Glad we were able to help! Love us? Write us a review! Rate CCM

CCM 5982 users have said thank you to us this month

excel987
Posts
3
Registration date
Tuesday June 11, 2019
Status
Member
Last seen
June 12, 2019
-
Hi ac3mark,
Thank you so much for your help. Your code worked perfectly.
Respond to ac3mark