Count cells with specific value in even columns
This tutorial shows how to count cells with specific value in even columns through the use of an Excel formula or VBA
Example: Count cells with specific value in even columns
=SUMPRODUCT(--(MOD(COLUMN(C8:I8),2)=0),--(C8:I8=C5))
|
This formula uses the Excel COLUMN and MOD functions to return the remainder of 0 for a cell in an even column and 1 for a cell in an odd column. The Excel SUMPRODUCT function then performs this calculation for every cell in the specified range (C8:I8) that contains the specific value (in this example the cell has to contain a value of 5) and returns the number of occurrences. In this example the formula will return a value of two given there are two cells in even columns (F8 and H8), within the selected range, that contain a value of 5.
|
Sub Count_cells_with_specific_value_in_even_columns()
'declare a variable
Dim ws As Worksheet
Dim ws As Worksheet
Set ws = Worksheets("Analysis")
'count cells with specific value in even columns
ws.Range("K8").Formula = "=SUMPRODUCT(--(MOD(COLUMN(C8:I8),2)=0),--(C8:I8=C5))"
ws.Range("K8").Formula = "=SUMPRODUCT(--(MOD(COLUMN(C8:I8),2)=0),--(C8:I8=C5))"
End Sub
ADJUSTABLE PARAMETERS
Output Range: Select the output range by changing the cell reference ("K8") in the VBA code.
Data Range: Select the values that you want to test and count by changing the range ("C8:I8") in the VBA code.
Specific Value: Select the value that you want to test and count for by changing the cell reference ("C5") in the VBA code.
Worksheet Selection: Select the worksheet in which you want to count cells with specific value in even columns 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.
Output Range: Select the output range by changing the cell reference ("K8") in the VBA code.
Data Range: Select the values that you want to test and count by changing the range ("C8:I8") in the VBA code.
Specific Value: Select the value that you want to test and count for by changing the cell reference ("C5") in the VBA code.
Worksheet Selection: Select the worksheet in which you want to count cells with specific value in even columns 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
This tutorial shows how to count the number of cells with a specific value in even columns in a selected range through the use of an Excel formula or VBA.
This tutorial provides one Excel method that can be applied to count the number of cells with a specific value in even columns from a selected range using the Excel SUMPRODUCT, MOD and COLUMN functions.
This tutorial provides one VBA method that can be applied to count the number of cells with a specific value in even columns from a selected range using the VBA formula and the exact same formula that is provided in the Excel method.
FORMULA
=SUMPRODUCT(--(MOD(COLUMN(range),2)=0),--(range=specific_value))
=SUMPRODUCT(--(MOD(COLUMN(range),2)=0),--(range=specific_value))
ARGUMENTS
range: A range of values that you want to test if there are cells in even columns that contain values and count the number of these occurrences.
specific_value: The specific value that you want to count for in the specified range.
range: A range of values that you want to test if there are cells in even columns that contain values and count the number of these occurrences.
specific_value: The specific value that you want to count for in the specified range.
RELATED TOPICS
Related Topic | Description | Related Topic and Description |
---|---|---|
Count cells with specific value in odd rows | How to count cells with specific value in odd rows using Excel and VBA methods | |
Count cells with specific value in even rows | How to count cells with specific value in even rows using Excel and VBA methods | |
Count cells with specific value in odd columns | How to count cells with specific value in odd columns using Excel and VBA methods | |
Count cells with values in odd rows | How to count cells with values in odd rows using Excel and VBA methods | |
Count cells with values in even rows | How to count cells with values in even rows using Excel and VBA methods |
RELATED FUNCTIONS
Related Functions | Description | Related Functions and Description |
---|---|---|
SUMPRODUCT Function | The Excel SUMPRODUCT function multiplies corresponding ranges and returns the sum of these values | |
MOD Function | The Excel MOD function returns the remainder after dividing a number by the divisor | |
COLUMN Function | The Excel COLUMN function returns the first column number of the selected reference |