[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Autofill Dynamic Range

Posted on 2013-12-23
6
Medium Priority
?
881 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 53

Expert Comment

by:Rgonzo1971
ID: 39736814
Hi,

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

Open in new window


Regards
0
 

Author Comment

by:maderitetech
ID: 39736830
Rgonzo1971,

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

Expert Comment

by:Rgonzo1971
ID: 39736838
Hi,

How do you define LastRow?

regards
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:maderitetech
ID: 39736858
LastRow is Long value, obtained by using the following code

LastRow = ActiveSheet.UsedRange.Rows.Count

Open in new window

0
 
LVL 53

Accepted Solution

by:
Rgonzo1971 earned 2000 total points
ID: 39736892
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
ID: 39736907
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

649 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