Sum values if cells contain text

To sum value if corresponding cells contain text you can apply the Excel SUMIF function

Example: Sum values if cells contain text

Sum values if cells contain text

METHOD 1. Sum values if cells contain text

EXCEL

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

METHOD 1. Sum values if cells contain text using VBA

VBA

Sub Sum_values_if_cells_contain_text()
'declare a variable
Dim ws As Worksheet
Set ws = Worksheets("Analysis")
'apply the formula to sum values if cells contain text
ws.Range("E5") = Application.WorksheetFunction.SumIf(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.
Sum Range: Ensure that the data you want sum is captured in range ("C5:C11").
Range: Ensure that the corresponding range to the sum 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.
Sum Range: Select the range that you want to sum 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 sum 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 sum values if cells contain text

EXPLANATION

EXPLANATION
To sum values if cells contain text you can apply the Excel SUMIF function.
FORMULA
=SUMIF(range, "*", sum_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 summed.
sum_range: The range of cells you want to sum from.