How to Count Cells that End with Specific Text in Excel

This post will guide you how to count the number of cells that end with a specific value within a range of cells using a formula in Excel 2013/2016 or Excel office 365. How do I count cells that end with a specific text through the use of VBA Macro in Excel.

Count Number of Cells that End with a Specific Text Through Formula


If you want to count the number of cells that end with a specific text value “el” in range B1:B6, and you can use the COUNTIF function to build a formula. And you need to use the asterisk(*) sign to count the number of cells that end with “el”. Just using the following formula:

=COUNTIF(B1:B6,”*ex”)

count cells that end with 1

LET’S SEE THAT HOW THIS FORMULA WORKS:

The COUNTIF function can be used to count the number of cells in the range that end with a specific text by matching the content of each cell against the pattern. And the asterisk sign is a wildcard that means “match any number of characters”.

Count Number of Cells that End with a Specific Text Through VBA


You can also use an VBA Macro to count cells if ends with a specific value in Excel. Just do the following steps:

Step1# open your excel workbook and then click on “Visual Basic” command under DEVELOPER Tab, or just press “ALT+F11” shortcut.

 Get the position of the nth using excel vba1

Step2#  then the “Visual Basic Editor” window will appear.

Step3# click “Insert” ->”Module” to create a new module.

convert column number to letter3

Step4# paste the below VBA code into the code window. Then clicking “Save” button.

count cells that end with 2

Sub CountCellsEndWith()
Dim ws As Worksheet
Set ws = Worksheets("Sheet3")
ws.Range("D1") = Application.WorksheetFunction.CountIf(ws.Range("B1:B6"), "*" & "el")

End Sub
x
How to Select Every Other Row in Excel

Note: you need to change the output range D1 to place the final result. And change the data range that you want to test the criteria against by changing the cell reference. You also need to change “el” pattern as you need .

Step5# back to the current worksheet, click on Macros button under Code group. then click Run button.

count cells that end with 3

Step6# let’s see the result:

count cells that end with 4

Related Functions


  • Excel COUNTIF function
    The Excel COUNTIF function will count the number of cells in a range that meet a given criteria. This function can be used to count the different kinds of cells with number, date, text values, blank, non-blanks, or containing specific characters. etc. = COUNTIF (range, criteria) …

 

Related Posts

If Cell is This Value or That Value

IF function is frequently used in Excel worksheet to return you expect “true value” or “false value” based on the result of logical test. If you want to see if a cell is A or B, and if one of ...

If Value is Greater Than A Certain Value
If Value is Greater Than A Certain Value 1

IF function is frequently used in Excel worksheet to return you expect “true value” or “false value” based on the logical test result. If you want to see if a value in one cell is greater than a specific value, ...

If Cell is Not Blank
If Cell is Not Blank 6

IF function is frequently used in Excel worksheet to return you expect “true value” or “false value” based on the result of created logical test. If you want to see if a cell is blank or not, and leave some ...

VBA Macro For VLOOKUP From Another Sheet
vba macro for vlookup from another sheet1

In the previous post, you should know that how to fix or remove the #N/A error when using VLOOKUP formula to lookup value from another sheet. And this post will show you how to use VBA code to vlookup data ...

If Cell is Blank
If Cell is Blank_1

IF function is frequently used in Excel worksheet to return you expect “true value” or “false value” based on the result of created logical test. If you want to see if a cell is blank or not, and leave some ...

If Cell Equals Certain Text String
If cell equals certain text_1

IF function is frequently used in Excel worksheet to return you expect “true value” or “false value” based on the result of created logical test. If you want to see if cell equals a certain text string like “Win”, you ...

If Cell Contains Either Text1 or Text2
If cell contains text1 or text2_1

IF function is frequently used in Excel worksheet to return “true value” or “false value” based on the logical test result. If you want to see if cell contains certain substring1 like “abc” or substring2 like “def”, and returns true ...

If Cell Contains Certain Text OR Equals Certain Text

IF cell equals certain text IF function is frequently used in Excel worksheet to return “true value” or “false value” based on the logical test result. If you want to test values to see if they equal certain text like ...

VLOOKUP From Another Sheet Not Working
vlookup from another sheet not working3

In the previous post, you should know that how to fix or remove the #N/A error when using VLOOKUP formula to lookup value from another sheet. And this post will show you reasons why your VLOOKUP formula is not working ...

If Cell Begins with One of Three Supplied Characters
If Cell Begins with One of Three Supplied Characters

If you want to test values to see if they begin with some given specific characters like “x”, ”y”, or “z”, you can create a formula with COUNTIF and SUM functions to return results. EXAMPLE You can see “TRUE” or ...

Sidebar