+ Reply to Thread
Results 1 to 11 of 11

UDF (like customised COUNT) ?

  1. #1
    Registered User
    Join Date
    11-17-2012
    Location
    Zurich
    MS-Off Ver
    Excel 2010
    Posts
    4

    Question UDF (like customised COUNT) ?

    Hi all, i have a column of 8760 values (total hours of a year) with zeros and non-zero values. I want to count the duration of the zero values, that is the sequential entries of zero values (which represent the hours of zero production for the power plant). More precisely, i want something like a COUNT function, which will add +1 for every sequential zero entry, when it finds a non-zero entry it stops (prints the till-that-entry result in a cell) and starts over.

    I have thought of a UDF (user defined function) that might work, but (1) i would like to hear if there's a faster/easier way and, if not, (2) what is missing from the code to work (i haven't used UDFs before).

    Thanks in advace

    Please Login or Register  to view this content.

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,929

    Re: UDF (like customised COUNT) ?

    i would suggest you upload a sample work book, (all sensitive data removed), showing what data you are working with, what your expected outcome is, and how you arrived at that

    To Attach a File:

    1. Click on Go Advanced
    2. In the frame Attach Files you will see the button Manage Attachments
    3. Click the button.
    4. A new window will open titled Manage Attachments - Excel Forum.
    5. Click the Browse... button to locate your file for uploading.
    6. This will open a new window File Upload.
    7. Once you have located the file to upload click the Open button. This window will close.
    8. You are now back in the Manage Attachments - Excel Forum window.
    9. Click the Upload button and wait until the file has uploaded.
    10. Close the window and then click Submit.
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Registered User
    Join Date
    11-17-2012
    Location
    Zurich
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: UDF (like customised COUNT) ?

    Thanks for the response; i think this can be solved without uploading any data.

    For example, assume we have column A:

    Please Login or Register  to view this content.
    What i am looking for is a function to print in column B
    Please Login or Register  to view this content.
    meaning that in column A from top to bottom i have first 4 sequential zeros, then 1 zero, then 3 sequential zeros and so on.
    Last edited by Athanasios2104; 11-17-2012 at 08:03 PM.

  4. #4
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: UDF (like customised COUNT) ?

    Maybe something like this:

    Please Login or Register  to view this content.
    It's not a UDF but it will accomplish the job.

    abousetta
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  5. #5
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: UDF (like customised COUNT) ?

    You could try an array formula instead, enter this formula in B2 and confirm it as an array with Shift Ctrl & Enter, then fill down as needed.

    Formula: copy to clipboard
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    11-17-2012
    Location
    Zurich
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: UDF (like customised COUNT) ?

    @abousetta: i still use as module through vba though, correct?

    @ jason: excel gives me "wrong formula" error when i try t

  7. #7
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: UDF (like customised COUNT) ?

    Yes, standard module.

    abousetta

  8. #8
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: UDF (like customised COUNT) ?

    Not sure what you mean by "wrong formula" error, you would need to translate the functions if you have excel installed in a language other than english, also regional settings might mean commas need to be changed to semicolons.

  9. #9
    Registered User
    Join Date
    11-17-2012
    Location
    Zurich
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: UDF (like customised COUNT) ?

    thanks for your answers guys, the solution my bro came up with is two simple IF functiosn and then finding min/max

    the values in examination are in column C, so with the following in column D:
    Please Login or Register  to view this content.
    and the following in column E:
    Please Login or Register  to view this content.
    i get the desired values of sequential zeros.


    /SOLVED

  10. #10
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: UDF (like customised COUNT) ?

    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:
    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

  11. #11
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,610

    Re: UDF (like customised COUNT) ?

    What about subtotals?
    Attached Files Attached Files
    Ben Van Johnson

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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