Excel formula to pull only certain text from row in CountIf

Posted on 2014-10-24
Medium Priority
Last Modified: 2014-10-24
I am trying to wrap my head around this and hoping you can help.

I have a workbook that has a pivot table that looks like this:

1.  Sheet 'Metrics'
     -  Column A contains Data that looks similar to this:                        
        [Accounting Export]-Bug-9923      
        [Accounting Export]-Bug-9937                        
        [Accounting Export]-User Story-2585

2.  Sheet      'Accounting Export' (no brackets) is created
     - Column A contains the id's 9923, 9937 etc.  There may be multiple columns with this data

3.  Back on the 'Metrics' sheet
     - Column B contains a CountIf.  The CountIf is to count all rows on the Accounting Export sheet that contain the ID.  So for our example; Give me a count of all the rows in column A of the Accounting Export sheet that contain 9923.  

   - I would like this count if formula to automatically look at the data in column A -  [Accounting Export]-Bug-9923 and use the text before the front hyphen (Accounting Export sheet (minus the brackets) to find the sheet to look in and after the last hyphen to find the id (9923).  There will always be brackets around the product to ignore and the number will always be after the last hyphen.

I was given something like:  COUNTIF(INDIRECT("'" & LEFT(A4,FIND("-",A4)-1) & "'!A1:A500" ),MID(A4,FIND("-",A4)+1,4)) but I can't seem to understand it enough to altar the way I need.
Question by:Katharina DuBose
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
LVL 27

Expert Comment

by:Glenn Ray
ID: 40402615
There are two issues.

First, the formula does not remove the square brackets from the string, so it's trying to look at a sheet named [Accounting Export].  Second, the function is not returning the rightmost digits after the second hyphen to add to the COUNTIF; it's getting the four after the first hyphen (ex., "Bug-").

If the IDs are always four digits, then this formula should return the correct value:
=COUNTIF(INDIRECT("'" & SUBSTITUTE(SUBSTITUTE(LEFT(A4,FIND("-",A4)-1),"[",""),"]","") & "'!A1:A500" ),RIGHT(A4,4))


Author Comment

by:Katharina DuBose
ID: 40402686
I can't seem to get it to register in the query.  The numbers will not always be 4 digit - they can range up to 6.  I tried with 4 digits and it fills the cell with the #VALUE!.  I've attached a file as an example.
LVL 27

Accepted Solution

Glenn Ray earned 2000 total points
ID: 40402732
Here's the revised formula to handle any number of digits:
=COUNTIF(INDIRECT("'" & SUBSTITUTE(SUBSTITUTE(LEFT(A4,FIND("-",A4)-1),"[",""),"]","") & "'!A1:A500" ),MID(A4,FIND("-",A4,FIND("-",A4)+1)+1,10))

See example workbook.

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

by:Katharina DuBose
ID: 40402753
I guess my copy is not working but it's working in the example.  I'll figure that out, perfect!  Thank you so much!

Author Closing Comment

by:Katharina DuBose
ID: 40402756
Thank you!
LVL 27

Expert Comment

by:Glenn Ray
ID: 40402764
Just check your cell references (A4 in the example) and make sure they're lining up with your PivotTable data.

Author Comment

by:Katharina DuBose
ID: 40402786
ok, thank you

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question