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

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

Cap percentage values between 0 and 100

This article will talk about how to cap the percentage values between 0% and 100% in Microsoft Excel Spreadsheet or Google Sheets. If you are a newbie on Excel or google Sheets, you may be able to do this by ...

Calculate Cap Percentages to Specific Value

This article will talk about how to limit the cap percentage of a given amount to a given value in Microsoft Excel Spreadsheet or Google Sheets. If you are a newbie on Excel or google Sheets, you may be able ...

Calculate Win Loss Tie

Suppose you got a task to calculate the win, loss, and tie totals; what would you do? If you are new to Ms Excel and don't have enough experience with it, then you might do this task manually but let ...

Calculate Years Between Dates In Ms Excel

If you are an avid Ms Excel user, then you might have come across a task in which you needed to calculate the years between the dates; you might take it easy and do this task manually, which is also ...

Calculate Number of Hours between Two Times

Calculating the difference between two times might be a valuable statistic for subsequent computations or averages, whether you're producing a time sheet for staff or recording personal exercises. While Excel has a plethora of complex functions, including date and time ...

Calculate Loan Interest in Given Year

When you borrow money, you are supposed to repay it gradually. Lenders, on the other hand, want to be compensated for their services and the risk they incur by lending you money. That is, you will not just repay the ...

Calculate Interest Rate for Loan

The interest rate is the fee charged by a lender to a borrower and is expressed as a percentage of the principal—the lent amount. The interest rate on a loan is often expressed as an annual percentage rate, abbreviated as ...

Calculate Interest for Given Period

Using the IPMT function in Excel, we can compute the interest payment on any loan. This step-by-step tutorial will guide Excel users of all skill levels through the process to calculate interest for given period. Finally, the formula: =IPMT(B3/12,1,B5,-B2) The ...

How To Use Excel GCD Function

This post will guide you how to use Excel GCD function with syntax and examples in Microsoft excel. Description The Excel GCD function Returns the greatest common divisor of two or more integers. So you can use the GCD function ...

Calculate A Ratio From Two Numbers In Excel

In elementary mathematics, a ratio is a connection or comparison between two or more integers. For example, ratios are often expressed as ":" to demonstrate the relationship between two numbers. You would think that manually calculating a ratio from two ...

Sidebar