We’d like to remind Forumites to please avoid political debate on the Forum.

This is to keep it a safe and useful space for MoneySaving discussions. Threads that are – or become – political in nature may be removed in line with the Forum’s rules. Thank you for your understanding.

📨 Have you signed up to the Forum's new Email Digest yet? Get a selection of trending threads sent straight to your inbox daily, weekly or monthly!

Excel CountIf Etc

I tried to this at work today and couldn't work out the correct formula so I ended up doing it by hand! :(

Here's the query...

Two columns; Amount and Reason(s):

Am | Re
20 | A
65 | BD
30 | C
55 | ABC
85 | DE
90 | AC

Now, I need to firstly count the number of entries for each reason letter. I tried, if I remember correctly, doing something like this: COUNTIF(B2:B7,"A"). It works for the entries with only one reason (in the example above it would count '1'), but for entries with multiple reasons it doesn't (it should count '3'). I tried the formula along with FIND() but with no luck. How can I do this?

Secondly I need to add up the total amount for each reason. Again, it would need to be able to include multiple reasons; in the example above the total amount for A would be (20+55+90), and B would be (65+55). How could I do this?

Thanks in advance, my head goes mushy after a while! :)

Comments

  • theCapt
    theCapt Posts: 223 Forumite
    got the 1st bit for you mate try this code and it should work:

    =COUNTIF(B2:B7,"A*")
    Scottish proverb - "Never drink whisky with water and never drink water without whisky"
  • Thanks, I didn't realise wildcards were supported. A quick search has shown me that =COUNTIF(B2:B7,"*B*") will do what I need as it should ignore anything before or after the 'B' etc.

    Now just to solve the second problem! :p
  • the second problem is a bit more tricky than than first.
    Scottish proverb - "Never drink whisky with water and never drink water without whisky"
  • theCapt wrote:
    the second problem is a bit more tricky than than first.

    Yup I kinda realised that ;) ... creating extra columns for A, B, C etc, then copying the amount value to the cell if the reason column contained the reason code, and adding up the total for the column, would work I think, but there must be a simpler way.
  • yep it is called SQL, but then it will be a database rather than a spreadsheet.

    infact it would be easier to do, using access than excel (using a database rather than a spreadsheet).
    Scottish proverb - "Never drink whisky with water and never drink water without whisky"
  • You will need to have your table as follows

    Re | Am
    A | 20
    BD | 65
    C |30
    ABC |55
    DE |85
    AC |90

    and then use =SUMIF(A2:B7,"*A*",B2:B7) and this gives 165
    Lightbulb moment = Jan 06 :mad:
    DFD Dec 2008 (According to the Snowball) :beer:
  • Why would you need to transpose the data :

    =SUMIF(B2:B7,"*a*",A2: A7)

    does it
This discussion has been closed.
Meet your Ambassadors

🚀 Getting Started

Hi new member!

Our Getting Started Guide will help you get the most out of the Forum

Categories

  • All Categories
  • 352.5K Banking & Borrowing
  • 253.7K Reduce Debt & Boost Income
  • 454.5K Spending & Discounts
  • 245.5K Work, Benefits & Business
  • 601.5K Mortgages, Homes & Bills
  • 177.6K Life & Family
  • 259.5K Travel & Transport
  • 1.5M Hobbies & Leisure
  • 16K Discuss & Feedback
  • 37.7K Read-Only Boards

Is this how you want to be seen?

We see you are using a default avatar. It takes only a few seconds to pick a picture.