+ Reply to Thread
Results 1 to 4 of 4

Defined Name assigned to cell, bulletproof way to read cell?

  1. #1
    Registered User
    Join Date
    02-20-2012
    Location
    Chicago, Illinois
    MS-Off Ver
    Excel 2010
    Posts
    25

    Defined Name assigned to cell, bulletproof way to read cell?

    Hello!

    I have an 2010 xlsm file that my VBA script must read ("harvest" as I like to say) the values of cells on various worksheets. Rows and columns can get moved around, so we used Defined Names to identify crucial cells for a safe and easy way to grab their value from VBA. My script is fairly large, and it's working well. I just ran into an issue (happily, before the VBA went into production!).

    I am Mr. Error Checker. I'm a very defensive programmer, and this has served me well in ExcelLand. I thought I had some good code for reading the values of cells in a way to avoid runtime errors if the cell has any variety of errors, e.g., #N/A, #VALUE!, etc. But I'm getting a runtime error 1004 with this code when I ran into a mistake with a Defined Name. I thought my code would gracefully handle the error!

    Here's the problem. I expected a particular cell's Defined Name to be, "ProjDet_AppNam" and that's what's in my VBA code. Turns out that in the spreadsheet, the actual Defined Name of the cell I was looking for was "ProjDet_AppNamCol". So I thought my defensive code would handle that gracefully, but it failed with a runtime 1004 error. (Naturally, I will correct the name of the Defined Name, but I have other similar code in my VBA who's robustness is now suspect.)

    Where did I go wrong?

    Note: My method is to first check that there are no errors in the cell--that it can be read without error--then I check if the cell is blank, null or empty.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Defined Name assigned to cell, bulletproof way to read cell?

    You never tested if the range exists at all:

    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    02-20-2012
    Location
    Chicago, Illinois
    MS-Off Ver
    Excel 2010
    Posts
    25

    Cool Re: Defined Name assigned to cell, bulletproof way to read cell?

    I had never seen this type of "Evaluate-ISREF" code before. Works like a champ. Once I know the Named Cell exists using this code, I am then proceeding with my other error-checking. Thank you very much Jerry!

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Defined Name assigned to cell, bulletproof way to read cell?

    Glad to help. A little snippet to add to the old toolbox.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] application-defined/object-defined error 1004 when trying to read from or write to cells
    By florin_excel in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-30-2012, 08:38 AM
  2. [SOLVED] Populate Cell with Assigned Cell Name
    By Toner in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-24-2012, 12:30 AM
  3. Replies: 8
    Last Post: 10-19-2012, 10:34 AM
  4. Replies: 3
    Last Post: 09-26-2012, 07:48 PM
  5. [SOLVED] How Can I read Hyperlink Assigned to a cell?
    By modytrane in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-18-2012, 11:09 PM

Tags for this Thread

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