Average values if cells contain text

To average value if corresponding cells contain text you can apply the Excel AVERAGEIF function

Example: Average values if cells contain text

Average values if cells contain text

METHOD 1. Average values if cells contain text

EXCEL

=AVERAGEIF(B5:B11,"*",C5:C11)
The formula uses the Excel AVERAGEIF function to average the numbers that have a text value in the corresponding cells in range (B5:B11).

METHOD 1. Average values if cells contain text using VBA

VBA

Sub Average_values_if_cells_contain_text()
'declare a variable
Dim ws As Worksheet
Set ws = Worksheets("Analysis")
'apply the formula to average values if cells contain text
ws.Range("E5") = Application.WorksheetFunction.AverageIf(ws.Range("B5:B11"), "*", ws.Range("C5:C11"))

End Sub

OBJECTS
Worksheets: The Worksheets object represents all of the worksheets in a workbook, excluding chart sheets.
Range: The Range object is a representation of a single cell or a range of cells in a worksheet.
PREREQUISITES
Worksheet Name: Have a worksheet named Analyst.
Average Range: Ensure that the data you want to average is captured in range ("C5:C11").
Range: Ensure that the corresponding range to the average range is captured in range ("B5:B11").
ADJUSTABLE PARAMETERS
Output Range: Select the output range by changing the cell reference ("E5") in the VBA code to any cell in the worksheet, that doesn't conflict with the formula.
Average Range: Select the range that you want to average by changing the range ("C5:C11") to any range in the worksheet, that doesn't conflict with the formula.
Range: Select the corresponding range to the average range by changing the range ("B5:B11") to any range in the worksheet, that doesn't conflict with the formula.

Explanation about the formula used to average values if cells contain text

EXPLANATION

EXPLANATION
To average values if cells contain text you can apply the Excel AVERAGEIF function.
FORMULA
=AVERAGEIF(range, "*", average_range)

ARGUMENTS
range: The range of cells you want to test the criteria against.
"*": The criteria that is used to determine which of the cells, from the specified range, should be averaged.
average_range: The range of cells you want to average from.