+ Reply to Thread
Results 1 to 8 of 8

vba on error event #value

  1. #1
    Registered User
    Join Date
    02-27-2013
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    38

    vba on error event #value

    hi forum I use this function that i use to remove the right side of a string!

    my problem is that sometimes i get an error (#value) to correct this problem i need to reference the cells again .

    the error happen when i drag a string on to the cell witch is referenced

    I need a macro to catch this error on event sample.xls

    the logic will be if error then reference again the cells


    Please Login or Register  to view this content.
    -v

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: vba on error event #value

    Hello cdafonseca,

    The problem looks like a referencing problem. By default, VBA variables are passed by Reference. This means the variable being must already be declared. If VBA discovers the variable has not been declared then an error occurs. The other method of referencing is by Value. VBA basically creates a copy of the variable to use in the procedure. Try the change below and see if it fixes your problem.

    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    02-27-2013
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    38

    Re: vba on error event #value

    thanks for the interest on this but it did not work for me


    the function works great but

    i only get this #ref error when i drag a string on to the cell instead copy and paste


    thats i need some code to run on error event

    if the cell shows #ref error then
    reference the cells again
    else
    do nothing


    else i need to rethink another way

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: vba on error event #value

    Hello cdafonseca,

    Trapping the error will only prevent the error from be displayed in the cell. However, the reference needed by the UDF (your macro) will still be invalid. You will have to manually reset it.

    The drag and drop feature does not work correctly with a UDF. There are many limitations on what a UDF can do. Unfortunately, I don't know of any workarounds for this problem.

  5. #5
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: vba on error event #value

    if you mean that you are dragging cells to create that REF error then it's no different from regular excel functions. if you use
    =REMOVE_RIGHT_SIDE(INDIRECT("A1"))
    the function works because the reference is not direct
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  6. #6
    Registered User
    Join Date
    02-27-2013
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    38

    Re: vba on error event #value

    Quote Originally Posted by JosephP View Post
    if you mean that you are dragging cells to create that REF error then it's no different from regular excel functions. if you use
    =REMOVE_RIGHT_SIDE(INDIRECT("A1"))
    the function works because the reference is not direct

    but can I use this if I need to reference from a different sheet?

  7. #7
    Registered User
    Join Date
    02-27-2013
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    38

    Re: vba on error event #value

    I have created a macro to correct the references make one step faster but I have created another problem!
    i want this macro to run automatically

    now by placing this formula
    Please Login or Register  to view this content.
    on my sheet i can return a number 1 on a cell if any the referenced cells result on an error


    is there a way to call a macro based on result of a formula?

  8. #8
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: vba on error event #value

    Quote Originally Posted by cdafonseca View Post
    but can I use this if I need to reference from a different sheet?
    yes-just include the sheet name

+ 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] 2 VBA codes under the same event - Ambiguous name error
    By michelle 1 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-12-2013, 05:28 AM
  2. How to change an event handler on error
    By alanb1976 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-08-2012, 08:07 AM
  3. Open Event Error
    By gumdrop in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-15-2010, 07:38 PM
  4. Error trapping for the Form_Activate() event
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-03-2006, 02:15 AM
  5. On Event calendar with error handling?
    By Chip in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-22-2005, 07:05 PM

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