+ Reply to Thread
Results 1 to 3 of 3

IF(ISERROR(VLOOKUP,"",VLOOKUP) in macro produces run-time error 1004

  1. #1
    Registered User
    Join Date
    05-18-2018
    Location
    Ohio, USA
    MS-Off Ver
    Excel 2013
    Posts
    11

    IF(ISERROR(VLOOKUP,"",VLOOKUP) in macro produces run-time error 1004

    My goal here is to set up a macro template file for a report that generates a new workbook every day. The item list is fluid, changing daily. The 2 vlookup functions are used to show what comments were given in the previous day's report for each item, as well as calculate how many days each item has been on this report. The problem I am experiencing is with the first vlookup; using the IF(ISERROR combination, I wanted to show a blank cell in the case of an #N/A error (no previous data for a particular item), so that once the macro runs and sets up the report, it is easy for users to input comments for items newly added to the report. When attempting to run the macro for testing, utilizing the following code:

    Please Login or Register  to view this content.
    VBA errors out with run-time error 1004, "application-defined or object-defined error". As far as I understand the concept, "" should result in a blank cell when the vlookup formula produces an error value. The really interesting part is that if I use this formula normally without VBA, it works mostly ok with no error messages from Excel, with the exception that some cells still end up showing "0" instead of blank. So why does VBA not like this formula??

    Please Login or Register  to view this content.
    This is the section of code I'm currently testing. I can provide further snippets or the entire macro if requested. "cellAddress" is declared and defined earlier in the macro, and works the way it's supposed to in every instance. The reason for using that variable instead of a specific cell reference is that the list of items in this report is never the same amount, so the last row is always different.

    Thank you for any and all help.
    Last edited by doleenovodno; 06-01-2018 at 09:39 AM.

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,800

    Re: IF(ISERROR(VLOOKUP,"",VLOOKUP) in macro produces run-time error 1004

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Click on Edit to open your thread, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: IF(ISERROR(VLOOKUP,"",VLOOKUP) in macro produces run-time error 1004

    You need to double up any quotes inside the formula string, like this
    Please Login or Register  to view this content.
    Also, the code and formula can be more efficient
    Please Login or Register  to view this content.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

+ 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] Vlookup error ["VLOOKUP evaluates to an out of bounds range" in Google Sheets]
    By Jietoh in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 7
    Last Post: 03-23-2017, 01:35 PM
  2. Replies: 4
    Last Post: 11-13-2015, 09:03 PM
  3. [SOLVED] Macro error "Error 1004" run time.
    By Maickol in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-30-2015, 10:47 AM
  4. Sheet9.Range("B2").Value VLOOKUP 1004 Error - Please Help!
    By froob in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-20-2015, 01:40 PM
  5. get "run time error 1004" when i try to activate macro on protected sheet why?
    By ASAFSWIS in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-19-2013, 11:37 AM
  6. [SOLVED] How to fix "Run-time error 13, type mismatch" when vlookup return value of #N/A?
    By ohlalayeah in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-02-2012, 02:01 AM
  7. Excel 2007 : Macro gives a "run time error '1004'"
    By grsnipe in forum Excel General
    Replies: 1
    Last Post: 10-15-2010, 02:37 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