How to Count Matching Name Pairs Across Excel Rows and Columns
Question details
The user needs to calculate the number of times two specific names are scheduled together in the same row across a multi-column dataset.

- Product
- Microsoft Excel (2013 and Microsoft 365)
- Device & OS
- not provided
- Scenario
- Tracking and counting the frequency of paired individuals (e.g., in a schedule or golfing foursome) across multiple weeks where names occupy different columns in the same row.
- Observed behavior
- A nested IF array formula comparing the entire data range to two individual criteria cells is returning 0 instead of the correct paired count because the array logic is improperly aligned.
Ensure that the names in your reference list exactly match the spelling and spacing of the names in your schedule range, as trailing spaces will cause formula matches to fail.
Use Helper Columns for Row-by-Row Evaluation
Using a helper column is the most reliable way to evaluate multiple conditions per row in older Excel versions like Excel 2013 without complex array logic.
When you use a formula like =SUM(IF(Range=Name1, IF(Range=Name2, 1, 0))), Excel checks if a single cell equals both names at the same time, which is impossible and returns 0. To fix this, you must evaluate the row as a whole.
By using COUNTIF on each row individually, you can verify if both names exist somewhere within that specific row.
Insert a new column next to your data range (for example, Column T). In the first data row (cell T4), prepare to enter your formula.
Type the formula: =IF(AND(COUNTIF(M4:S4, Golfer!$B$2)>0, COUNTIF(M4:S4, Golfer!$B$13)>0), 1, 0) and press Enter.
Select cell T4, click and drag the fill handle down to the bottom of your data (e.g., cell T330).
In your result cell (e.g., Sheet 2 C3), use a simple SUM formula like =SUM(Foursome!T4:T330) to get the total count of matching pairs.

Use Dynamic Arrays with BYROW (Microsoft 365 Only)
If you are using a newer version of Excel, you can use dynamic array formulas to perform row-by-row checks without creating helper columns.
Analyze Pairs using Power Query
Power Query can transform your schedule into a clean, unpivoted dataset, making it easy to group and count any combinations of names.
Calculate and Manage Complex Schedules with WPS Office
WPS Spreadsheet provides powerful data analysis tools and full compatibility with advanced Excel formulas. Whether you prefer using helper columns, SUMPRODUCT, or array formulas, WPS Office handles complex row-by-row evaluations effortlessly.
- 1. Open Your Schedule: Launch WPS Spreadsheet and open your existing .xlsx schedule workbook.
- 2. Apply Logic Formulas: Use built-in functions like COUNTIF across your rows to detect the presence of specific names.
- 3. Aggregate Data Quickly: Sum your logical results using the AutoSum feature to instantly see how often two people are paired together.

Frequently Asked Questions
Why does my nested IF array formula return 0 instead of the correct count?
Your original formula evaluates the entire multi-column range at once. If you ask Excel if a cell equals Name1 AND Name2, it will always be false because a single cell cannot hold two different values simultaneously. Checking the range row-by-row using COUNTIF or helper columns resolves this.
Do I need to use Ctrl+Shift+Enter for these matching formulas?
If you use the Helper Column method with standard COUNTIF functions, you only need to press Enter. Traditional array formulas in older versions of Excel (like Excel 2013) do require Ctrl+Shift+Enter, but they are generally harder to troubleshoot.
Can I count matches if the names appear in different columns each week?
Yes. By using the COUNTIF(range, criteria)>0 logic, you are asking Excel to look at the entire row across all selected columns. As long as the name appears anywhere in that row, it will be counted as a match.




