Solved

Autofill Dynamic Range

Posted on 2013-12-23
6
539 Views
Last Modified: 2013-12-23
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.
0
Comment
Question by:maderitetech
  • 3
  • 3
6 Comments
 
LVL 48

Expert Comment

by:Rgonzo1971
Comment Utility
Hi,

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

Open in new window


Regards
0
 

Author Comment

by:maderitetech
Comment Utility
Rgonzo1971,

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

Expert Comment

by:Rgonzo1971
Comment Utility
Hi,

How do you define LastRow?

regards
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:maderitetech
Comment Utility
LastRow is Long value, obtained by using the following code

LastRow = ActiveSheet.UsedRange.Rows.Count

Open in new window

0
 
LVL 48

Accepted Solution

by:
Rgonzo1971 earned 500 total points
Comment Utility
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
 

Author Comment

by:maderitetech
Comment Utility
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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Excel and Formulas 8 30
Indirect formula 9 28
second highest value difference 11 23
Excel VBA - open a DataValidation dropdown 6 19
Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
Dealing with unintended Excel Active-X resizing quirks (VBA code simulates "self correction") David Miller (dlmille) Intro Not everyone is a fan of Active-X controls in spreadsheets (as opposed to the UserForm approach, the older Form controls …
Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now