+ Reply to Thread
Results 1 to 5 of 5

UDF used in formula will not calculate

  1. #1
    Registered User
    Join Date
    09-24-2013
    Location
    Montgomery, TX
    MS-Off Ver
    Excel 2013
    Posts
    6

    UDF used in formula will not calculate

    Using VBA I entered a function (found online) to be used in a cell formula. The function and the formula work, but the cell that contains the formula will not update automatically; Calculations are set to automatic. To make the formula work I have to place my cursor behind the formula and enter.

    Excel Version: Microsoft® Excel® for Microsoft 365 MSO (16.0.13029.20342) 64-bit

    My formula: =(CheckRegister[[#Totals],[WITHDRAWAL]]-SUMCOLOR(G5,CheckRegister[WITHDRAWAL]))

    My UDF Code: Function SumColor(rColor As Range, rSumRange As Range)

    Dim rCell As Range

    Dim iCol As Integer

    Dim vResult

    iCol = rColor.Interior.ColorIndex

    For Each rCell In rSumRange

    If rCell.Interior.ColorIndex = iCol Then

    vResult = WorksheetFunction.Sum(rCell) + vResult

    End If

    Next rCell

    SumColor = vResult

    End Function

  2. #2
    Registered User
    Join Date
    07-02-2013
    Location
    Cheshire
    MS-Off Ver
    Office Professional 2007
    Posts
    79

    Re: UDF used in formula will not calculate

    Hi there. You need to tell excel that this function is volatile (i.e. calculated evry time anthing changes on the sheet. Do it like this:
    Please Login or Register  to view this content.
    Please be aware that having a lot of volatile functions will slow excel down.

  3. #3
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,430

    Re: UDF used in formula will not calculate

    The formula will not be calculated if you are simply changing the colour of a cell.

    The Application.Volatile should not be necessary in this case as the formula will recalculate whenever the Total row of the table recalculates.
    Cheers
    Andy
    www.andypope.info

  4. #4
    Registered User
    Join Date
    09-24-2013
    Location
    Montgomery, TX
    MS-Off Ver
    Excel 2013
    Posts
    6

    Re: UDF used in formula will not calculate

    Thank you both for your reply. The formula does recalculate based on cell color when the total column updates, my issue is I need the formula to update when the cell color changes. Often in this spreadsheet, the only change will be to the cell color, i.e. change cell color to GREEN when paid, RED when past due, YELLOW if an issue, etc. maclearyj code while very much appreciated did not resolve my issue, probably because I was not clear in that I needed the formula to update on "any" change of cell color. Any ideas on how to make this formula work when the cell or cells in the range change color?

  5. #5
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,430

    Re: UDF used in formula will not calculate

    Changing cell colour does not raise any event.

    Instead you could try using the selection change event, and from there calculate the cell.

+ 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. Replies: 1
    Last Post: 08-17-2019, 01:26 PM
  2. Replies: 1
    Last Post: 01-07-2018, 10:30 AM
  3. Replies: 1
    Last Post: 01-11-2016, 02:31 PM
  4. Replies: 1
    Last Post: 01-08-2015, 07:02 PM
  5. Replies: 2
    Last Post: 05-13-2014, 01:18 PM
  6. Replies: 3
    Last Post: 03-28-2013, 12:41 PM
  7. Replies: 1
    Last Post: 02-02-2013, 02:28 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