Avatar of maderitetech
maderitetech
 asked on

Autofill Dynamic Range

I'm creating a macro that fills a range that changes every time it is run. The only thing consistent about the range is that it begins on row 7 of the active cell. The column filled changes every time. The number of rows may change. Therefore code like the following will not work.

Range("A2").AutoFill Destination:=Range("A2:A" & LastRow)

Open in new window

I need something more dynamic like this.
ActiveCell.AutoFill Destination:=Range(ActiveCell.Address & ":" & ActivceCell.Column & LastRow)

Open in new window

That will not work because the column property of the active cell returns a number, not a column letter. I maybe could try to convert the number to a letter, but it gets complicated after the letter Z.
Is there any way to auto-fill a completely dynamic range? (Well, as close to dynamic that I can think of.)
I also have tried substituting the Cells function inside of the Range function. No go.
Microsoft Excel

Avatar of undefined
Last Comment
maderitetech

8/22/2022 - Mon
Rgonzo1971

Hi,

pls try
ActiveCell.AutoFill Destination:=Range(ActiveCell, Cells(LastRow, ActiveCell.Column))

Open in new window


Regards
maderitetech

ASKER
Rgonzo1971,

Returns the same error when I tried to use Cells() - Runtime 1004
Method 'Range' of object'_Global' failed.
Rgonzo1971

Hi,

How do you define LastRow?

regards
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
maderitetech

ASKER
LastRow is Long value, obtained by using the following code

LastRow = ActiveSheet.UsedRange.Rows.Count

Open in new window

ASKER CERTIFIED SOLUTION
Rgonzo1971

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
maderitetech

ASKER
I was just heading that way myself, since I didn't see anything else that would work.
You're right. That works.
What a pity we still have to parse strings.
Thank you!