+ Reply to Thread
Results 1 to 9 of 9

Excel VBA function returning #VALUE! unexpectedly (and only occasionally)

  1. #1
    Registered User
    Join Date
    12-17-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    4

    Excel VBA function returning #VALUE! unexpectedly (and only occasionally)

    Hello all,
    This one has me stumped. This simple function compares data from a table, and adds values if the input string matches data in the first column of that table:

    Please Login or Register  to view this content.
    This worked beautifully when I first wrote it. Now, after adding new rows to the table "Balances", any sums corresponding to those new lines break the function: #VALUE! is returned, and the script doesn't ever hit
    Please Login or Register  to view this content.
    (a breakpoint set there never triggers). However, any lines in the table from when I originally wrote this return the correct sum! Anybody have any ideas?? FYI, Win7 and Office2007 Enterprise.

    Thanks!

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Excel VBA function returning #VALUE! unexpectedly (and only occasionally)

    I'm not sure what the problem is. I suspect it has to do, in part, with the data.

    Can I ask why you don't just use the SUMIF function?
    =SUMIF(A:A,Account,C:C)
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Excel VBA function returning #VALUE! unexpectedly (and only occasionally)

    Hi novaraz

    Welcome to the Forum!!!

    Set your Break Point higher in the Code and step through it; perhaps here.

    Please Login or Register  to view this content.
    or here
    Please Login or Register  to view this content.
    The Code is not getting to your existing Break Point...something's making it skip that Line of Code.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  4. #4
    Registered User
    Join Date
    12-17-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Excel VBA function returning #VALUE! unexpectedly (and only occasionally)

    I don't use SUMIF because I do more complicated calculations under this loop. The problem is in the equality statement; a break doesn't trigger for any of the new 'accounts', even if the function is pointing to the element being compared...

    If I change the contents of an original table row, the function works fine. If I change both a old row and a new row (so should result in the sum of their values in column C), it fails, after successfully comparing the values in the 'old' row.

  5. #5
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Excel VBA function returning #VALUE! unexpectedly (and only occasionally)

    Quote Originally Posted by novaraz View Post
    I don't use SUMIF because I do more complicated calculations under this loop. The problem is in the equality statement; a break doesn't trigger for any of the new 'accounts', even if the function is pointing to the element being compared...

    If I change the contents of an original table row, the function works fine. If I change both a old row and a new row (so should result in the sum of their values in column C), it fails, after successfully comparing the values in the 'old' row.
    Can you attach an example file with a data table?

  6. #6
    Registered User
    Join Date
    12-17-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Excel VBA function returning #VALUE! unexpectedly (and only occasionally)

    I just sanitized my workbook, and if course it works fine now. Including if I add new rows to the table. Let me double check all the references in my original workbook, I'll post when I figure it out.

  7. #7
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Excel VBA function returning #VALUE! unexpectedly (and only occasionally)

    Check your "unsanitized" Table for it's scope...perhaps you need something like this...
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    12-17-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Excel VBA function returning #VALUE! unexpectedly (and only occasionally)

    So strange, everything seems to work now. The only thing I changed was the formula input on the worksheet, so that it used table notation instead of cell address. Thanks for the help. I'm hesitant to mark the thread SOLVED, since I'm not sure what changed and why it works.

  9. #9
    Forum Expert
    Join Date
    05-01-2014
    Location
    California, US
    MS-Off Ver
    Excel 2010
    Posts
    1,795

    Re: Excel VBA function returning #VALUE! unexpectedly (and only occasionally)

    Quote Originally Posted by novaraz View Post
    So strange, everything seems to work now. The only thing I changed was the formula input on the worksheet, so that it used table notation instead of cell address. Thanks for the help. I'm hesitant to mark the thread SOLVED, since I'm not sure what changed and why it works.
    Wild guess.... Some of the "numbers" might have been entered into Excel as text initially. But when you made changes, you might have inadvertently "re-entered" them, for example by causing Excel to re-interpret the cell contents as truly numeric. This is not unusual if we copy text (e.g. from a webpage) and paste directly into Excel.

+ 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] VBA function returning #value in excel
    By mat888 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-03-2015, 12:25 PM
  2. Replies: 1
    Last Post: 03-11-2013, 09:06 AM
  3. Replies: 1
    Last Post: 12-09-2011, 12:46 AM
  4. Replies: 3
    Last Post: 06-30-2006, 08:10 PM
  5. Excel VBA window appear unexpectedly.... Really annoying
    By TKovacs in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-18-2006, 02:40 PM
  6. Replies: 0
    Last Post: 02-09-2006, 11:45 PM
  7. Excel Calculations Open in Manual Occasionally
    By rich32822 in forum Excel General
    Replies: 1
    Last Post: 02-18-2005, 10:06 AM

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