+ Reply to Thread
Results 1 to 6 of 6

Dynamic Range for macro

  1. #1
    Registered User
    Join Date
    01-05-2010
    Location
    Lausanne, Switzerland
    MS-Off Ver
    Excel 2003
    Posts
    7

    Dynamic Range for macro

    Hi,

    I've a coding issue I've been unable to solve so far and google didn't help this time..

    I'd need to define a range starting at the last used cell of column Q and finishing at the last row used in column A (Columns A to I are getting datas from an external source)

    I had no problem to find how to start at last used cell, but I can't find the trick to define where the range has to stop.

    I actually uses a named range, based on column A length, to run a query but it starts therefore at the beginning of the columns and uses times/ressources for "nothing"..



    Here's the named range I actually use in my macro :

    =Sheet1!$Q$2:INDEX(Sheet1!$Q:$Q;COUNTA(Sheet1!$A:$A))
    Any idea how I could solve this ?
    Thanks in advance for your support,

    regards
    steve
    Last edited by soakaos; 11-11-2010 at 11:46 AM.

  2. #2
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Dynamic Range for macro

    Post deleted as I'm unable to read questions properly today

    Dom
    Last edited by Domski; 11-11-2010 at 07:31 AM.
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  3. #3
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Dynamic Range for macro

    =offset(a1;counta(q:q);0;counta(a:a)-counta(q:q);16)



  4. #4
    Registered User
    Join Date
    01-05-2010
    Location
    Lausanne, Switzerland
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Dynamic Range for macro

    Hi,

    Thanks for your answers.

    Snb : unfortunately, your solution doesn't work..

    but I've found a solution through this piece of code :
    Dim Plg As Range
    Set Plg = Range([Q65000].End(xlUp)(2), [A65000].End(xlUp).Offset(, 16))
    Maybe Domski will understand the question better with the answer..

    Thanks again for your support,
    have a nice evening (it's 5pm here..)

    Steve

  5. #5
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Dynamic Range for macro

    This was the answer I originally posted which turns out was correct:

    Please Login or Register  to view this content.

    It's best not to hard code row numbers like 65000 into your code as the number of rows in different versions of Excel now vary.

    Dom

  6. #6
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Dynamic Range for macro

    The solution is even simpler:

    =offset(Q1,counta(q:q),0,counta(a:a)-counta(q:q),0)

+ 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