+ Reply to Thread
Results 1 to 7 of 7

IF function working with LEN and Substitute

Hybrid View

  1. #1
    Registered User
    Join Date
    04-12-2012
    Location
    leicester
    MS-Off Ver
    Excel 2003
    Posts
    3

    IF function working with LEN and Substitute

    Hi

    I have a formula that looks up the number of occurances of a single character in a column, some cells contain more than one character.

    =SUM(LEN(range)-LEN(SUBSTITUTE(range,"A","")))

    I want to add an IF function to this so that it will only carry out the above formula IF a certain word appears in another column of that same row? But then I don't want this to cancel out and return a 0 if the word does not appear in a row.

    Row 1 Row 2
    Red .........A
    Blue..........A
    Red .........A
    Red......... A

    For example with the above if the certain word was "red" it will only return a value of 3 as the 2nd column should not count.

    Any help would be appreciated

    Thanks
    Last edited by cd109; 04-12-2012 at 08:13 AM.

  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: IF function working with LEN and Substitute

    Try something like this:

    =SUMPRODUCT(--($A$1:$A$4 = "Red"), --($B$1:$B$4 = "A"))
    _________________
    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 DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: IF function working with LEN and Substitute

    assuming column A has your words, B has your count of letters you can use this

    =SUMPRODUCT(ISNUMBER(FIND("Red",A1:A4))*B1:B4)

    without B you could use this:

    =SUMPRODUCT(ISNUMBER(FIND("Red",A1:A4))*SUM(LEN(A1:A4)-LEN(SUBSTITUTE(A1:A4,"A",""))))
    If you liked my solution, please click on the Star -- to add to my reputation

    If your issue as been resolved, please clearly state so and mark the thread as [SOLVED] using the thread tools just above the first post.

  4. #4
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,703

    Re: IF function working with LEN and Substitute

    Try

    =SUMPRODUCT((A1:A4="Red")+0,LEN(B1:B4)-LEN(SUBSTITUTE(B1:B4,"A","")))
    Audere est facere

  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: IF function working with LEN and Substitute

    Or a correction on mine:

    =SUMPRODUCT(--($A$1:$A$4="red"),--(ISNUMBER(SEARCH("A", $B$1:$B$4))))

  6. #6
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: IF function working with LEN and Substitute

    a note on the solution i provided, i was under the impression that both the word and letter being searched for were in the same cell.

  7. #7
    Registered User
    Join Date
    04-12-2012
    Location
    leicester
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: IF function working with LEN and Substitute

    Thanks all - I'm going to try some of these this afternoon and let you know - can't get on the spreadsheet at the moment - its a shared one at work!

    Really appreciate your help!

+ 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