Excel Formula to Match Gender and Shift to a Sleeping Location
Question details
The user needs an Excel formula to assign the first available sleeping location based on multiple criteria (gender and shift) while excluding locations that have already been assigned.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Assigning accommodations from a master list to personnel based on specific demographic and scheduling requirements without double-booking.
- Observed behavior
- A dynamic formula is required in the assignment column to look up available locations from another sheet and return a unique assignment for each person.
Ensure that your source data on the Sleep Master worksheet and your target data on the Storm Team worksheet have consistent formatting and clear columns for Gender and Shift to allow accurate multi-criteria matching.
Use an Array Formula with INDEX, MATCH, and COUNTIF
This solution uses a combination of lookup and counting functions to match multiple conditions while dynamically excluding values already present in your assignment column.
By combining INDEX and MATCH with Boolean logic, you can check for multiple conditions simultaneously. Adding COUNTIF ensures the formula skips locations that have already been assigned in previous rows.
Check your Storm Team worksheet to confirm that Gender is in column B and the Shift (Day/Night) value is in column E.
In your assignment column (e.g., cell W2), you will need a dynamic range to check for existing assignments, such as COUNTIF($W$1:W1, SleepMasterLocations)=0. This ensures duplicate locations are flagged.
Build the MATCH array to look for the number 1 (True). The logic will look like: (SleepMasterGender=B2)*(SleepMasterShift=E2)*(COUNTIF($W$1:W1, SleepMasterLocations)=0).
Wrap the MATCH function inside an INDEX function pointing to your Sleep Master locations list. Enter the formula as an array formula (using Ctrl+Shift+Enter if on older versions of Excel).
Drag the formula down to subsequent rows and verify that when assigning a specific room (like 1551-ASU-2-D), the formula does not assign it again to the next person matching the same criteria.

Easily Handle Complex Array Formulas in WPS Spreadsheet
WPS Spreadsheet offers powerful built-in functions to effortlessly manage multi-criteria lookups and array formulas. You can seamlessly assign and organize complex data schedules without worrying about compatibility issues.
- 1. Open Your Workbook: Launch WPS Spreadsheet and open your scheduling workbook.
- 2. Input the Lookup Formula: Select the target cell in column W and type your INDEX/MATCH array formula.
- 3. Use Formula Evaluation: Go to the Formulas tab and use the Evaluate Formula tool to step through your conditions and ensure duplicate prevention works correctly.

Frequently Asked Questions
How do I match multiple criteria without using array formulas?
If your spreadsheet version supports it, you can use the XLOOKUP function or the FILTER function combined with INDEX to match multiple criteria without needing traditional Ctrl+Shift+Enter array execution.
Why is my lookup formula assigning the same location twice?
This happens if your formula does not track previously assigned locations. You must include a dynamic COUNTIF range (like $W$1:W1) within your criteria array to exclude locations that have already been returned in the rows above.
What does the #N/A error mean in my assignment column?
An #N/A error means the formula could not find any available location that matches both the gender and shift criteria while also meeting the condition of not being previously assigned.




