+ Reply to Thread
Results 1 to 5 of 5

Excel 2007 : Odd Counting Question

Hybrid View

  1. #1
    Registered User
    Join Date
    09-08-2011
    Location
    Philadelphia, USA
    MS-Off Ver
    Excel 2007
    Posts
    3

    Odd Counting Question

    I manage a sales team, and I keep track of their data on Excel.

    What I'd like to know if there is any function to write that would count the numbers in another cell.

    For example, Column E is tracking "Total Sales" whereas Column L is tracking "Total $ Amount of Sales" which I manually enter. So my question is if Column L is entered as " =24+30+60+60" is there any formula to write that would give me "4" in Column E.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Odd Counting Question

    Not with an inbuilt function, but you can add a user-defined-function to your workbook to do that.
    Function COUNTP(Ref As Range) As Long
    'Counts the number of items in a cell's formula
    'as determined by + and - operators
        COUNTP = Len(Ref.Cells(1, 1).Formula) - _
            Len(Replace(Replace(Ref.Cells(1, 1).Formula, "+", ""), "-", "")) + 1
    End Function

    How to install the User Defined Function:

    1. Open up your workbook
    2. Get into VB Editor (Press Alt+F11)
    3. Insert a new module (Insert > Module)
    4. Copy and Paste in your code (given above)
    5. Get out of VBA (Press Alt+Q)
    6. Save as a macro-enabled workbook

    The function is installed and ready to use.

    If your formula were in cell A1, then in another cell enter this to get the count of items in that formula:
    =COUNTP(A1)
    Last edited by JBeaucaire; 10-04-2011 at 10:26 AM. Reason: Corrected sample formula at end of post
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Odd Counting Question

    Quote Originally Posted by JBeaucaire View Post
    =COUNT(A1)
    Will return the result of 1. I take it the P is silent, as in 'swimming pool'

  4. #4
    Registered User
    Join Date
    09-08-2011
    Location
    Philadelphia, USA
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Odd Counting Question

    Sounds dynamite. I'll give it a try today, and if this works, would save me a lot of time!
    Last edited by shg; 10-05-2011 at 11:13 AM. Reason: deleted quote

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Odd Counting Question

    Great. Oh, and please do not QUOTE my entire posts into yours. Just use the Quick Reply button. Much easier to read threads.

+ 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