+ Reply to Thread
Results 1 to 7 of 7

autofill in macro range is constant- how can I code to be a variable range?

  1. #1
    Registered User
    Join Date
    01-26-2010
    Location
    united states
    MS-Off Ver
    Excel 2003/Excel 2007
    Posts
    27

    autofill in macro range is constant- how can I code to be a variable range?



    I am trying to write a macro which will autofill specific columns. The macro will set the range from the start of my autofill to the end of my autofill as a constant range.
    The problem I need to get around is the end of my range can always change each time I run the macro. For instance, the first time I run the macro I may only need to autofill from row 4 to row 15. The next time, I may only need to autofill from row 4 to 23 (because of user updates). How can I make the end of my range not be a constant address but variable?


    Range("AR4:AW4").Select
    Selection.AutoFill Destination:=Range("AR4:AW15") <---- 15 changes from day to day
    Last edited by [email protected]; 02-20-2010 at 12:50 AM.

  2. #2
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: autofill in macro range is constant- how can I code to be a variable range?

    It's easy enough to do, but how do you determine what the last row is? Is there a flag, or some other way to tell? If so, it can likely be incorporated into the macro.

  3. #3
    Registered User
    Join Date
    01-26-2010
    Location
    united states
    MS-Off Ver
    Excel 2003/Excel 2007
    Posts
    27

    Re: autofill in macro range is constant- how can I code to be a variable range?

    That's my problem. There is no flag. The only way I can identify what the last row is to go to the beginning of the cell, hold down the <shift> <end> and then arrow downn key. That will bring me to the last row, but how do you save that reference and incorporate it into the macro autofill range?

  4. #4
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: autofill in macro range is constant- how can I code to be a variable range?

    Ok... so you have a column of data, and you want the filldown to the end of that column?

    Essentially you just said that you use Shift+End+DownArrow. I'm assuming that's because you're at the top of a column of data, and you want to select all the way down to the end of that column. Yes? If so, based on your example is that column AR?

    You might try something like:
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    01-26-2010
    Location
    united states
    MS-Off Ver
    Excel 2003/Excel 2007
    Posts
    27

    Re: autofill in macro range is constant- how can I code to be a variable range?

    Almost. But still can't get it. Here is an example

    ......A .....B.......C..............................AR.........AS..........AT.......AU.......AV......AW
    .4...xx...xxx.....xxx...........................xxxx......xxxx.......xxxx.....xxxx....xxxx....xxxx
    .5...xx...xxx.....xxx................................................................................................
    .6...xx...xxx.....xxx................................................................................................
    .7...xx...xxx.....xxx................................................................................................
    .8 ..xx...xxx.....xxx...............................................................................................
    .9...xx...xxx.....xxx................................................................................................
    10..xx...xxx.....xxx...............................................................................................


    The spreadsheet would always have values in the first couple of columns. In this case, my last row row is row 10. I would then need to autofill columns AR:AW through row 10.
    I tried you last suggestion, but it only filled one extra row.
    Last edited by [email protected]; 02-20-2010 at 12:37 AM.

  6. #6
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: autofill in macro range is constant- how can I code to be a variable range?

    You missed part of my post then.
    If so, based on your example is that column AR?
    Based on your latest post, that is column A (or B or C). So change the code to:
    Please Login or Register  to view this content.
    This will find the last used row in column A, and use that to set the filldown limit.

  7. #7
    Registered User
    Join Date
    01-26-2010
    Location
    united states
    MS-Off Ver
    Excel 2003/Excel 2007
    Posts
    27

    Re: autofill in macro range is constant- how can I code to be a variable range?

    It worked. Thanks so much. -Marie

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1