+ Reply to Thread
Results 1 to 5 of 5

User defined function to calculate difference

  1. #1
    Registered User
    Join Date
    07-07-2009
    Location
    Louisiana, United States
    MS-Off Ver
    Excel 2007
    Posts
    19

    Thumbs up User defined function to calculate difference

    Thanks guys, I figured it out and you helped a bunch.

    Hi All I'm having difficulty getting a custom formula to calculate the difference between the value of cells in adjacent columns.

    Specifically, I am tracking the difference between "BeginTime" represented in column A and EndTime in Column B. The "Difference" between the two is calculated in Column C.
    Please Login or Register  to view this content.
    works just fine, and I can drag that formula down as far i want. So I wouldn't really need a custom function but I do not want the consequential value of "0" that appears cells that aren't used yet.

    The following code does absolutely nothing and I'm stuck on how to fix it. any suggestions are appreciated.

    Please Login or Register  to view this content.
    Last edited by antonymiller; 06-16-2010 at 03:38 PM. Reason: Solved

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: User defined function to calculate difference

    UDF's are generally slower than native functions.

    Couldn't you just use a pre-emptive COUNT test ?

    =IF(COUNT(A2:B2)<2,"",B2-A2)

    (depending on the nature of the values in A2:B2 you might need to adjust your difference calculation)

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: User defined function to calculate difference

    You shouldn't need code,use an If function to check if a cellis used

    =IF(ISBLANK(A1),"",A1-B1)
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  4. #4
    Registered User
    Join Date
    07-07-2009
    Location
    Louisiana, United States
    MS-Off Ver
    Excel 2007
    Posts
    19

    Question Re: User defined function to calculate difference

    Thanks Donkey and royUK,

    I had already gone that route.... the problem is when I drag these formula's down the length of the "Difference" column, the unused cells display a value of 0.00 whereas i would prefer that they simply remain blank. Getting them to remain blank after the calculation is thing i'm struggling with. My bad, I should have been more clear on that.

    Thanks again.

  5. #5
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: User defined function to calculate difference

    You've marked this Solved yet final post implies unresolved ?

    FWIW, in the case of the COUNT ex. you would only get a numeric output if both start & end are complete (use of COUNT assumes valid (date)Time entries of course).

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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