Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, and 2016. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Counting Wins and Losses.

Counting Wins and Losses

by Allen Wyatt
(last updated February 13, 2016)

5

In Excel, Graham has created a matrix of player names for his league. Cells B2:H2 contain the names of the players, as do cells A3:A9. At each intersection in the matrix, Graham places a "W" or "L" to indicate whether the match-up resulted in a win or loss for the player in each row. If a player plays another person more than once, then a cell contains a "W" or "L" for each game. Graham was wondering what formula could be used, starting in column I, to indicate the number or wins and losses for each player.

There are a number of ways you can get the desired information. One is to use this type of formula:

=LEN(SUBSTITUTE(B3&C3&D3&E3&F3&G3&H3,"L",""))

This formula calculates the number of non-L characters in row 3—in other words, the number of wins. It does this by concatenating the contents of B3:H3, and then using the SUBSTITUTE function to remove all the Ls. This leaves the Ws, which are counted by the LEN function. You could also use the CONCATENATE function, in the following manner, for the same result:

=LEN(SUBSTITUTE(CONCATENATE(B3,C3,D3,E3,F3,G3,H3),"L",""))

To calculate the number of losses, simply replace "L" in each formula with "W".

You can also use an array formula, which allows you to specify a range of cells to examine, rather than needing to specify every single cell:

=SUM(LEN(SUBSTITUTE(B3:H3, "L","")))

This array formula, entered by pressing Shift+Ctrl+Enter, returns the number of wins (W characters) in the range B3:H3.

Finally, you can use a user-defined function to return the occurrences of a specific character within a given range. The following macro will do the trick:

Function CharNums(r, chr) As Integer
    Dim c As Range
    Dim strX As String
    Dim J As Integer

    Application.Volatile
    CharNums = 0
    For Each c In r.Cells
        strX = c.Value
        For J = 1 To Len(strX)
            If Mid(strX, J, 1) = chr Then CharNums = CharNums + 1
        Next J
    Next c
End Function

To use the function, you would us a formula like this in your worksheet:

=CharNums(B3:H3;"W")

The function returns the number of uppercase W characters in the range. All other characters (including lowercase w characters) are ignored. To count losses, simply substitute L for W in the formula.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (11650) applies to Microsoft Excel 2007, 2010, 2013, and 2016. You can find a version of this tip for the older menu interface of Excel here: Counting Wins and Losses.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Transposing Two Characters

If you have two characters in the wrong order, you might be interested in a shortcut you can use to switch their order. ...

Discover More

Negatives in Pie Charts

Pie charts are a great way to graphically display some types of data. Displaying negative values is not so great in pie ...

Discover More

Converting Text to Uppercase in a Macro

Macros are often used to process documents. If part of the processing involves making text selections uppercase, Word ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More ExcelTips (ribbon)

Returning the Minimum of Integers of a Range

If you have a range of numbers that contain both integers and decimal numbers, you may have a need to determine the ...

Discover More

Adding Up Tops and Bottoms

When you are working with sequenced values in a list, you’ll often want to take some action based on the top X or ...

Discover More

Totaling Across Worksheets

Want to sum the values in the same cell on a range of worksheets? It's not as easy as summing a range on the same ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is seven less than 9?

2016-02-15 09:23:27

Robert Dambold

Why not just use the COUNTIF function instead of being too complicated on it. this formula allows you to set the range and what identifier you are looking for. If you are using a simple "W" or "L" in one column to indicate how many wins or losses, it works very well. I have used this for softball/baseball statistics and fantasy football leagues for years.


2016-02-15 06:18:58

GRH

Zeddy, COUNTIF does not meet this requirement in the question:

"If a player plays another person more than once, then a cell contains a "W" or "L" for each game"

In other words, the cell might correctly contain "WW" "LL" or even "WLW"


2016-02-14 08:05:24

zeddy

I would point out the superiority and simplicity of the built-in COUNTIF function.
If a cell contains "WL" it will NOT be included in the =Countif total for either a Win or a Loss, neither would a mis-typed cell entry of "WW"

A single cell entry of "w" WILL be counted as a Win (as case is ignored).
The =LEN(..) formula would double-count an entry like "WW", but this is not double-counted with the =Countif method.

A cell entry like "Waiting result" would be treated as a "Win" using the =LEN method


2016-02-13 17:35:54

Chad

I would point out the superiority of the function. Specifically the key words "All other characters..." in the second last sentence. The function is counting the instances of the character requested. All the formulas shown are assuming that there are only two characters W or L in the cells. Should someone accidently enter W L or enter all in the format W,L this would have the effect of increasing the count. You could use:
=LEN(CONCATENATE(B3,C3,D3,E3,F3,G3,H3))-LEN(SUBSTITUTE(CONCATENATE(B3,C3,D3,E3,F3,G3,H3),"W",""))
To count the number of 'W'ins. Which would match the function.


2016-02-13 05:05:49

zeddy

..or just use the formula
=COUNTIF(B3:H3,"W")


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.