Count cells that end with "...-ABC"

WildWill

Board Regular
Joined
Sep 10, 2009
Messages
92
Hi

I have a data range (A1:D10) with data which contains any random text prefix but which will always end with a "-" followed by 3 Alphanumeric characters, e.g.:

Andy-DRA
Rob-M&R
Peter-MUR
Andrew-DRA
Will-DRA

I want to count all cells which end with a specific criteria, e.g. If In cell E1, I enter "DRA", then the answer in F1 should be "3". What type of formula can I use?

Thanks!
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
This code will always keep the search limited to cells in A1:D10.
Code:
Function CountCombos(SearchStr As String)
    For RowCount = 1 To 10
        For ColCount = 1 To 4
            If Right(Cells(RowCount, ColCount), 3) = SearchStr Then
                CurrCount = CurrCount + 1
            End If
        Next
    Next
    CountCombos = CurrCount
End Function

The function may be entered into a new module and called from any cell like this:

=CountCombos(E1)
 
Upvote 0
Just in case there are any names ending in DRA (like Sandra, maybe?), I'd use

=COUNTIF(A1:D10,"*-"&E1)
 
Upvote 0
Ive just tried both formulas above

could someone explain the "*" to me please

BTW "*_" only returned the 1 with the _ in it
 
Upvote 0
It's a wildcard character, so:

*xyz* This will look for strings that contain xyz
*xyz This will look for strings that end with xyz
xyz* This will look for strings that start with xyz
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,351
Members
452,907
Latest member
Roland Deschain

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top