+ Reply to Thread
Results 1 to 8 of 8

Determine if named range is empty / null

  1. #1
    Forum Contributor beeawwb's Avatar
    Join Date
    01-04-2004
    Location
    Perth, WA, Australia
    MS-Off Ver
    Microsoft Office Excel 2003 (11.8146.8221) SP2
    Posts
    105

    Determine if named range is empty / null

    Hi all,

    This will probably turn out to be a really quick one: I've got some named ranges I'm working with that in of themselves use Offset to automatically expand a list.

    Please Login or Register  to view this content.
    How would I programatically determine if there's nothing in the range? I need to trap for instances where the users choose to work with the list, but haven't entered any items into it. E.g... (which obviously doesn't work!)

    Please Login or Register  to view this content.
    Cheers,
    Bob
    Last edited by beeawwb; 12-02-2008 at 12:22 AM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    What happens when you type this in the Immediate window:

    ? Range("BrandList").Count
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Contributor beeawwb's Avatar
    Join Date
    01-04-2004
    Location
    Perth, WA, Australia
    MS-Off Ver
    Microsoft Office Excel 2003 (11.8146.8221) SP2
    Posts
    105
    Hi shg,

    I get "Run-time error '1004': Application-defined or object-defined error". I was originally going to test if Count = 0, but it throws that error before doing the comparison.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    Yup. I was wondering if you would get "Object required".

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor beeawwb's Avatar
    Join Date
    01-04-2004
    Location
    Perth, WA, Australia
    MS-Off Ver
    Microsoft Office Excel 2003 (11.8146.8221) SP2
    Posts
    105
    Just to see if things were working, I've made a new module and pasted in the function. I've made a new Sub (Testit) which is quite simply...

    Please Login or Register  to view this content.
    If I choose a range that I know has cells in it, e.g. CACList, it returns False, as we'd expect. However, when using BrandList, which is empty, I get...

    Run-time error '1004':
    Method 'Range' of object '_Global' failed

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    Mmmm. That code was designed for a range that has had all its cells deleted. Stand by ...

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    try this (untested):
    Please Login or Register  to view this content.

  8. #8
    Forum Contributor beeawwb's Avatar
    Join Date
    01-04-2004
    Location
    Perth, WA, Australia
    MS-Off Ver
    Microsoft Office Excel 2003 (11.8146.8221) SP2
    Posts
    105
    Bingo, that's gotten it. Thanks for your help as always!

+ 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