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.
maderitetechAsked:
Who is Participating?
 
Rgonzo1971Connect With a Mentor Commented:
Hi,
if you want to use the letter pls try

LastRow = ActiveSheet.UsedRange.Rows.Count
strColumn = Split(ActiveCell.Address, "$")(1)
ActiveCell.AutoFill Destination:=Range(ActiveCell, Range(strColumn & LastRow))

Open in new window

0
 
Rgonzo1971Commented:
Hi,

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

Open in new window


Regards
0
 
maderitetechAuthor Commented:
Rgonzo1971,

Returns the same error when I tried to use Cells() - Runtime 1004
Method 'Range' of object'_Global' failed.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Rgonzo1971Commented:
Hi,

How do you define LastRow?

regards
0
 
maderitetechAuthor Commented:
LastRow is Long value, obtained by using the following code

LastRow = ActiveSheet.UsedRange.Rows.Count

Open in new window

0
 
maderitetechAuthor Commented:
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!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.