+ Reply to Thread
Results 1 to 9 of 9

Thread: Naming Ranges

  1. #1
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Manchester England
    MS-Off Ver
    Excel 2010
    Posts
    197

    Naming Ranges

    Hi,
    I like to define a dynamic range in the define name window as follows
     =Offset($A$1,0,0,Counta($A:$A),Counta($1:$1)
    This works fine as long as all the cells in col A and row 1 are filled.
    If this is not the case I have defined the range in VBA. using rows.count and columns.count

    I now have a situation where I would like to define a dynamic range which may easily have lots of empty cerlls using the define name window. I have not been able to find worksheet functions to do the job.
    Can anyone help please
    John
    Last edited by j_Southern; 02-13-2012 at 09:57 AM.

  2. #2
    Forum Guru Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    MS Excel 2010
    Posts
    2,252

    Re: Naming Ranges

    Try this

    =OFFSET($A$1,0,0,MATCH(REPT("z",99),$A:$A),MATCH(REPT("z",99),$1:$1))

  3. #3
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Manchester England
    MS-Off Ver
    Excel 2010
    Posts
    197

    Re: Naming Ranges

    Hi,
    Thanks for your help, but that doesn't work.
    John

  4. #4
    Forum Guru NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    32,636

    Re: Naming Ranges

    What kind of data do you have in Column A and Row 1?
    Microsoft MVP - Excel

    Where there is a will there are many ways. Pick One!


    Please read the Forum Rules

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

    Preferred Charities: Lupus Canada and Sick Kids Foundation.
    Feel Free to Donate if you want to, for the assistance you received today.

  5. #5
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Manchester England
    MS-Off Ver
    Excel 2010
    Posts
    197

    Re: Naming Ranges

    A mixture of strings and numbers and blanks
    John

  6. #6
    Forum Guru NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    32,636

    Re: Naming Ranges

    Try:

    =Sheet1!$A$1:INDEX(Sheet1!$1:$1048576,MAX(IFERROR(MATCH(9.999E+307,Sheet1!$A:$A),0),IFERROR(MATCH(REPT("z",255),Sheet1!$A:$A),0)),MAX(IFERROR(MATCH(9.999E+307,Sheet1!$1:$1),0),IFERROR(MATCH(REPT("z",255),Sheet1!$1:$1),0)))
    This takes into account that it might be possible to have only text (and blanks) or only numbers (and blanks) too...
    Microsoft MVP - Excel

    Where there is a will there are many ways. Pick One!


    Please read the Forum Rules

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

    Preferred Charities: Lupus Canada and Sick Kids Foundation.
    Feel Free to Donate if you want to, for the assistance you received today.

  7. #7
    Forum Guru Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    MS Excel 2010
    Posts
    2,252

    Re: Naming Ranges

    Quote Originally Posted by j_Southern View Post
    A mixture of strings and numbers and blanks
    John
    =OFFSET($A$1,0,0,MAX(IFERROR(MATCH(99^99,$A:$A),0),IFERROR(MATCH(REPT("z",99),$A:$A),0)),MAX(IFERROR (MATCH(99^99,$1:$1),0),IFERROR(MATCH(REPT("z",99),$1:$1),0)))

  8. #8
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Manchester England
    MS-Off Ver
    Excel 2010
    Posts
    197

    Re: Naming Ranges

    Thank you all for your help. Both methods work. I shall use the shorter one.
    It does seem odd that there isn't a function like VBA CurrentRegion which would make it easier to name a range containing blank cells..
    John

  9. #9
    Forum Guru NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    32,636

    Re: Naming Ranges

    Though note that shorter isn't always most ideal.. some functions are Volatile....
    Microsoft MVP - Excel

    Where there is a will there are many ways. Pick One!


    Please read the Forum Rules

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

    Preferred Charities: Lupus Canada and Sick Kids Foundation.
    Feel Free to Donate if you want to, for the assistance you received today.

+ 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.2.0