Count cells if begins with

This tutorial shows how to count the number of cells that begin with a specific value through the use of Excel formulas or VBA

Example: Count cells if begins with

Count cells if begins with

METHOD 1. Count cells if begins with a specific value using a cell reference

EXCEL

=COUNTIF(B8:B14,C5&"*")
This formula uses the Excel COUNTIF function combined with the asterisk (*) sign to count the number of cells in range (B8:B14) that begin with "b", which is specified in cell C5. The asterisk (*) represents one or more characters.

METHOD 2. Count cells if begins with a specific value with value directly entered into the formula

EXCEL

=COUNTIF(B8:B14,"b*")
This formula uses the Excel COUNTIF function combined with the asterisk (*) sign to count the number of cells in range (B8:B14) that begin with "b", which is entered directly into the formula. The asterisk (*) represents one or more characters.

METHOD 1. Count cells if begins with a specific value by referencing to a cell using VBA

VBA

Sub Count_cells_if_begins_with_a_specific_value()
'declare a variable
Dim ws As Worksheet
Set ws = Worksheets("Analysis")
'count the number of cells in range (B8:B14) that begin with "b", which is specified in cell (C5)
ws.Range("E8") = Application.WorksheetFunction.CountIf(ws.Range("B8:B14"), ws.Range("C5") & "*")

End Sub

ADJUSTABLE PARAMETERS
Output Range: Select the output range by changing the cell reference ("E8") in the VBA code.
Specific Value: Select the specific value that you want to count for when the cells in range ("B8:B14") begin with this value, by changing the value in cell reference ("C5") in the VBA code.
Date Range: Select the range that you want test the criteria against by changing the range reference ("B8:B14") in the VBA code.
Worksheet Selection: Select the worksheet, by changing the Analysis worksheet name in the VBA code, which captures a range of cells from which you want to count the number of cells that begin with a specific value and the worksheet must also capture the specific value itself. You can also change the name of this object variable, by changing the name 'ws' in the VBA code.

METHOD 2. Count cells if less than or equal to a specific value with the value entered directly into the VBA code

VBA

Sub Count_cells_if_begins_with_a_specific_value()
'declare a variable
Dim ws As Worksheet
Set ws = Worksheets("Analysis")
'count the number of cells in range (B8:B14) that begin with "b"
ws.Range("E8") = Application.WorksheetFunction.CountIf(ws.Range("B8:B14"), "b*")

End Sub

ADJUSTABLE PARAMETERS
Output Range: Select the output range by changing the cell reference ("E8") in the VBA code.
Specific Value: Select the specific value that you want to count for when the cells in range ("B8:B14") begin with this value, by changing the value "b" in the VBA code.
Date Range: Select the range that you want test the criteria against by changing the range reference ("B8:B14") in the VBA code.
Worksheet Selection: Select the worksheet which captures a range of cells from which you want to count the number of cells that begin with a specific value by changing the Analysis worksheet name in the VBA code. You can also change the name of this object variable, by changing the name 'ws' in the VBA code.

Explanation about the formula used to count cells if begins with a specific value

EXPLANATION

EXPLANATION
This tutorial shows how to count cells that begin with a specific value using Excel formulas and VBA.
This tutorial provides two Excel method that can be applied to count cells that begin with a specific value by using an Excel COUNTIF function and the "*" criteria. The first method references to a cell for the specific value and in the second method the specific value is directly entered into the formula. The formulas count the cells from range (B8:B14) that start with letter "b".
This tutorial provides two VBA methods that can be applied to count cells that begin with a specific value. The first method references to a cell for the specific value and in the second method the specific value is directly entered into the VBA code.
FORMULA (with value referenced to a cell)
=COUNTIF(range, value&"*")
FORMULA (with value directly entered into the formula)
=COUNTIF(range, "value*")
ARGUMENTS
range: The range of cells you want to count from.
value: The value that the cell begins with.

RELATED TOPICS

Related Topic Description Related Topic and Description
How to count cells that end with a specific value using Excel and VBA methods
How to count cells that contain a specific value using Excel and VBA methods
How to count cells that do not contain a specific value using Excel and VBA methods
How to count cells that are greater than a specific value using Excel and VBA methods
How to count cells that are less than a specific value using Excel and VBA methods

RELATED FUNCTIONS

Related Functions Description Related Functions and Description
The Excel COUNTIF function returns the number of cells in a range that meet a specified criteria