+ Reply to Thread
Results 1 to 16 of 16

Exclude values within brackets from my formula.

  1. #1
    Registered User
    Join Date
    11-24-2013
    Location
    Florida
    MS-Off Ver
    Excel 2010
    Posts
    7

    Question Exclude values within brackets from my formula.

    Good Evening. I am working on a project where I need to tally the number of times "31" appears in a cell. An example of my cell data is as follows.

    Column C

    31\31\7\6\31\31 [1]
    31\5\1\6\31\31 [21]
    31\31\7\6\31\31 [658]
    31\31\5\6\31\16 [1731]

    The formula I have created to count the occurrences is as follows:

    =(LEN(C1)-LEN(SUBSTITUTE(C1,"31","")))/2

    I am sure I coded this wrong, because it would always double the actual occurrences of 31. I divided it by 2 and it worked, but I am sure there is a better way to do it.

    However my main problem is what happens if "31" appears within the brackets (EXAMPLE 4), as I do not want that to be a part of my calculations. What modification to my formula would enable me to ignore the values within brackets. I appreciate any help that could be given. Thank you for reading.

  2. #2
    Forum Expert dredwolf's Avatar
    Join Date
    10-27-2012
    Location
    Clearwater,Canada
    MS-Off Ver
    Excel 2007
    Posts
    2,649

    Re: Exclude values within brackets from my formula.

    your formula looks like about the simplest for that case, the reason you have to divide by 2 to get the count is that 31 is 2 characters long, so each time you replaced it with "", you removed 2 chars from the text

    as for your other question, I see a couple of issues with offerring a solution without a sample showing what you would expect,
    #1, {1731} we know the 31, because you've told us, but how is Excel supposed to know its a 2 digit number or whether the 17 is a 1 and a 7 or 17 etc
    #2 what are the expected limits (number) of excluded numbers ?
    #3 the explanation is a little vague, do you want the numbers within the brackets to be counted, and if so how (individually, as a group) ? or do you want a count of the remaining numbers, and again how ?

    a sample workbook showing a few examples with the expected results would help considerably

    Too Attach a sample workbook. Make sure there is just enough data to make it clear what is needed. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are demonstrated, mock them up manually if needed. Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic
    A picture may be worth a thousand words, BUT, a sample Workbook is worth a thousand screenshots!
    -Add a File - click advanced (next to quick post), scroll to manage attachments, click, select add files, click select files, select file, click upload, when file shows up at bottom left, click done (bottom right), click submit
    -To mark thread Solved- go top of thread,click Thread Tools,click Mark as Solved
    If you received helpful response, please remember to hit the * of that post

  3. #3
    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: Exclude values within brackets from my formula.

    This got a bit messy, but it works...
    =SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(C1,"\31","xx"),"31x","xx"),"31\","xx")
    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

  4. #4
    Registered User
    Join Date
    11-24-2013
    Location
    Florida
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Exclude values within brackets from my formula.

    Thank you for your reply. To answer your questions:
    1: That is a good point. I am still pretty new at excel.
    2: The values within the brackets can be from 0 to 4999. In theory, I could exclude every number above and below exactly 31 within that range.
    3: I with for the numbers in the brackets to be ignored completely from the formula. I only want to count the instances of 31 that appear next to the \'s

    I have attached a sample worksheet as requested. Thanks again for your attention.
    31List.xlsx

  5. #5
    Registered User
    Join Date
    11-24-2013
    Location
    Florida
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Exclude values within brackets from my formula.

    Quote Originally Posted by FDibbins View Post
    This got a bit messy, but it works...
    =SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(C1,"\31","xx"),"31x","xx"),"31\","xx")
    I tried this but it did not work. With the data C1 being:

    31\31\15\25\31\31 [1947]

    I received this output:

    xxx\15\25xxxx [1947]

  6. #6
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Exclude values within brackets from my formula.

    Try this...

    Please Login or Register  to view this content.
    EDIT: I had to put code tags around the formula to prevent the forum software from trimming out the extra space characters!
    Last edited by Tony Valko; 11-24-2013 at 07:48 PM.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  7. #7
    Registered User
    Join Date
    11-24-2013
    Location
    Florida
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Exclude values within brackets from my formula.

    Quote Originally Posted by Tony Valko View Post
    Try this...

    Please Login or Register  to view this content.
    EDIT: I had to put code tags around the formula to prevent the forum software from trimming out the extra space characters!
    This worked like a charm! Thank you!

  8. #8
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Exclude values within brackets from my formula.

    You're welcome. Thanks for the feedback!

  9. #9
    Valued Forum Contributor
    Join Date
    10-29-2012
    Location
    Mojokerto,Indonesia
    MS-Off Ver
    Excel 2007
    Posts
    554

    Re: Exclude values within brackets from my formula.

    try this one
    =(LEN(LEFT(C1,FIND("[",C1)-1))-LEN(SUBSTITUTE(LEFT(C1,FIND("[",C1)-1),31,"")))/2

  10. #10
    Forum Expert dredwolf's Avatar
    Join Date
    10-27-2012
    Location
    Clearwater,Canada
    MS-Off Ver
    Excel 2007
    Posts
    2,649

    Re: Exclude values within brackets from my formula.

    So, you JUST wnat the 31's with no numbers before or after, just the "\31\"'s counted (and if at the start or end ie "31\...", "....\31") ?

    if so this nasty one will work:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Hope this helps :

  11. #11
    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: Exclude values within brackets from my formula.

    Quote Originally Posted by faithhammer View Post
    I tried this but it did not work. With the data C1 being:

    31\31\15\25\31\31 [1947]

    I received this output:

    xxx\15\25xxxx [1947]
    LOL sorry, I forgot to do the count part...
    =LEN(C1)-LEN(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(C1,"\31","xx"),"31x","xx"),"31\","xx"))

  12. #12
    Registered User
    Join Date
    11-24-2013
    Location
    Florida
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Exclude values within brackets from my formula.

    Quote Originally Posted by Ghozi Alkatiri View Post
    try this one
    =(LEN(LEFT(C1,FIND("[",C1)-1))-LEN(SUBSTITUTE(LEFT(C1,FIND("[",C1)-1),31,"")))/2
    This one also works, but produces an error if the cell it is referring to is blank. Thanks!

  13. #13
    Registered User
    Join Date
    11-24-2013
    Location
    Florida
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Exclude values within brackets from my formula.

    Quote Originally Posted by FDibbins View Post
    LOL sorry, I forgot to do the count part...
    =LEN(C1)-LEN(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(C1,"\31","xx"),"31x","xx"),"31\","xx"))
    This one worked also, thanks. Amazing how everyone's code differs but still has the same effect!

  14. #14
    Registered User
    Join Date
    11-24-2013
    Location
    Florida
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Exclude values within brackets from my formula.

    Quote Originally Posted by dredwolf View Post
    So, you JUST wnat the 31's with no numbers before or after, just the "\31\"'s counted (and if at the start or end ie "31\...", "....\31") ?

    if so this nasty one will work:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Hope this helps :
    I tried this one, but all it came back with were 0's for every value. I appreciate the time you took in this matter however, thank you very much

  15. #15
    Forum Expert dredwolf's Avatar
    Join Date
    10-27-2012
    Location
    Clearwater,Canada
    MS-Off Ver
    Excel 2007
    Posts
    2,649

    Re: Exclude values within brackets from my formula.

    Not sure why you got zeros, I got the same values you have in the upload

    And, you are welcome!, whether it works for you or not, thanks for the acknowledgement
    Attached Files Attached Files
    Last edited by dredwolf; 11-24-2013 at 10:01 PM.

  16. #16
    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: Exclude values within brackets from my formula.

    Quote Originally Posted by faithhammer View Post
    This one worked also, thanks. Amazing how everyone's code differs but still has the same effect!
    Yes that is 1 of the big things about excel, more often than not, there are many ways to get to the same answer - different members have their own preferences and pet functions they reply on, and we are all constantly learning from each other!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. sum formula to exclude zero values
    By nmginn in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-14-2013, 04:19 PM
  2. Formula to Exclude Duplicate Values
    By jjcgirl in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-22-2013, 11:43 AM
  3. Replies: 5
    Last Post: 04-19-2012, 09:02 AM
  4. Sumproduct Formula - How Do I Exclude Values
    By winnie_shrub in forum Excel General
    Replies: 3
    Last Post: 04-14-2009, 06:32 AM
  5. Formula to add numbers and exclude text values
    By jpruffle in forum Excel General
    Replies: 7
    Last Post: 04-01-2009, 05:26 AM

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