find range based on 2 cell criteria

Akira181

Board Regular
Joined
Mar 23, 2010
Messages
67
Office Version
  1. 365
Platform
  1. Windows
It's been a while since I've last used excel and I'm having a complete mental block today.

I have a calendar tracking multiple people in Column A, and Column B to Column R has the data. The month data is split into two "arrays" of 15 days. So the same person appears twice in one month over two rows if that makes sense.

What I'm trying to do is that when I have selected a name and month, I'd like it to find the two corresponding rows and apply a formula to them (such as count the number of days that say "training" for example)

I tried named the ranges by month, splitting by names and data so I'm only looking for the name in a defined month. So "Jan_Name" for Column A, and "Jan_23" for the data range then using Xlookup twice (one to search top down, the other bottom up)to try and find the corresponding row but I'm not having any joy. Also tried combinations of H/V lookup, index, match with less joy.

Can someone help?
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Are you able to use XL2BB to share the layout of the sheet?

Remove any sensitive information
 
Upvote 0
Employee schedule rev01.xlsx
ABCDEFGHIJKLMNOPQR
1Jan-23january
2
3NamesSundayMondayTuesdayWednesdayThursdayFridaySaturdaySundayMondayTuesdayWednesdayThursdayFridaySaturday
41234567891011121314
5Person AHolidaytrainingtrainingtrainingtrainingtrainingtrainingTrainingTrainingTrainingTrainingTrainingTraining
6Person BHolidayHolidayOfficeOfficeOfficeofficeofficeofficeofficeofficeoffice
7Person CHolidayofficeofficeofficeofficeofficeofficeofficeofficeoffice
8Person DHolidayofficeofficeofficeofficeOfficeOfficeOfficeOfficeOffice
9Person EHolidayHolidaytrainingtrainingtrainingtrainingtrainingtrainingtrainingtrainingtrainingtrainingtraining
10SundayMondayTuesdayWednesdayThursdayFridaySaturdaySundayMondayTuesdayWednesdayThursdayFridaySaturdaySundayMondayTuesday
111516171819202122232425262728293031
12Person AtrainingTrainingofficeofficeholidayHolidayOfficeOfficeTrainingOfficeOfficeSiteSite
13Person BOfficeSiteSiteSiteSiteSiteSiteSiteSiteSiteSiteSiteSiteSiteSiteOfficeSite
14Person CHolidayofficeofficeofficeofficeOfficeOfficeOfficeHolidayHolidayOfficeOffice
15Person DofficeofficeofficeofficeofficeOfficeOfficeOfficeOfficeHolidayHolidayOffice
16Person ETrainingTrainingTrainingTrainingofficeOfficeOfficeOfficeOfficeOfficeTrainingTrainingTraining
Timetable (2)
Cells with Data Validation
CellAllowCriteria
A5:A9Any value
A4:P4Any value
A12:A16Any value


I was expecting more of a fight to get XL2BB installed on the work laptop but seems to went smoothly. I've posted one month, I have the same layout for each month in the same worksheet. No idea where the data validation part came from though.

So for example, I would like to count the number of days Person A spent in the "Office" for January. I'm trying to use a formula to automate it as much as possible because person A or the month may change.
 
Upvote 0
Perhaps the below will help:
Book1
ABCDEFGHIJKLMNOPQRSTUV
101/01/2023January
2
3JanuaryNamesSundayMondayTuesdayWednesdayThursdayFridaySaturdaySundayMondayTuesdayWednesdayThursdayFridaySaturdayMonthJanuary
4January1234567891011121314NamePerson A
5JanuaryPerson AHolidaytrainingtrainingtrainingtrainingtrainingtrainingTrainingTrainingTrainingTrainingTrainingTrainingFind Whattraining
6JanuaryPerson BHolidayHolidayOfficeOfficeOfficeofficeofficeofficeofficeofficeofficeCount15
7JanuaryPerson CHolidayofficeofficeofficeofficeofficeofficeofficeofficeoffice
8JanuaryPerson DHolidayofficeofficeofficeofficeOfficeOfficeOfficeOfficeOffice
9JanuaryPerson EHolidayHolidaytrainingtrainingtrainingtrainingtrainingtrainingtrainingtrainingtrainingtrainingtraining
10JanuarySundayMondayTuesdayWednesdayThursdayFridaySaturdaySundayMondayTuesdayWednesdayThursdayFridaySaturdaySundayMondayTuesday
11January1516171819202122232425262728293031
12JanuaryPerson AtrainingTrainingofficeofficeholidayHolidayOfficeOfficeTrainingOfficeOfficeSiteSite
13JanuaryPerson BOfficeSiteSiteSiteSiteSiteSiteSiteSiteSiteSiteSiteSiteSiteSiteOfficeSite
14JanuaryPerson CHolidayofficeofficeofficeofficeOfficeOfficeOfficeHolidayHolidayOfficeOffice
15JanuaryPerson DofficeofficeofficeofficeofficeOfficeOfficeOfficeOfficeHolidayHolidayOffice
16JanuaryPerson ETrainingTrainingTrainingTrainingofficeOfficeOfficeOfficeOfficeOfficeTrainingTrainingTraining
17
1801/02/2023February
19
20FebruaryNamesSundayMondayTuesdayWednesdayThursdayFridaySaturdaySundayMondayTuesdayWednesdayThursdayFridaySaturday
21February1234567891011121314
22FebruaryPerson AHolidaytrainingOfficeOfficetrainingtrainingtrainingTrainingTrainingTrainingTrainingTrainingTraining
23FebruaryPerson BHolidayHolidayOfficeOfficeOfficeofficeofficeofficeofficeofficeoffice
24FebruaryPerson CHolidayofficeofficeofficeofficeofficeofficeofficeofficeoffice
25FebruaryPerson DHolidayofficeofficeofficeofficeOfficeOfficeOfficeOfficeOffice
26FebruaryPerson EHolidayHolidaytrainingtrainingtrainingtrainingtrainingtrainingtrainingtrainingtrainingtrainingtraining
27FebruarySundayMondayTuesdayWednesdayThursdayFridaySaturdaySundayMondayTuesdayWednesdayThursdayFridaySaturdaySundayMondayTuesday
28February1516171819202122232425262728293031
29FebruaryPerson AtrainingTrainingofficeofficeholidayHolidayOfficeOfficeTrainingOfficeOfficeSiteSite
30FebruaryPerson BOfficeSiteSiteSiteSiteSiteSiteSiteSiteSiteSiteSiteSiteSiteSiteOfficeSite
31FebruaryPerson CHolidayofficeofficeofficeofficeOfficeOfficeOfficeHolidayHolidayOfficeOffice
32FebruaryPerson DofficeofficeofficeofficeofficeOfficeOfficeOfficeOfficeHolidayHolidayOffice
33FebruaryPerson ETrainingTrainingTrainingTrainingofficeOfficeOfficeOfficeOfficeOfficeTrainingTrainingTraining
Sheet1
Cell Formulas
RangeFormula
V6V6=LET( tc,TOCOL(FILTER(C3:S33,(A3:A33=V3)*(B3:B33=V4))), ROWS(FILTER(tc,tc=V5)))
A3:A16A3=$N$1
A20:A33A20=$N$18
Cells with Data Validation
CellAllowCriteria
V3ListJanuary,February
 
Upvote 1
Solution
that works perfectly but completely not the way I was thinking of doing it (probably why it wasn't working). Never used the LET function before.

I'm assuming tc is a user defined variable? Bit confused as to how it's working
 
Upvote 0
thanks for that. Last question, I'm using a VBA code I found on google to count when certain cells are a different colour (red in this case)

Is there any way to make that work in combination with the LET function Georgieboy wrote? Basically to count the number of red cells per person per month (cell content doesn't matter)

VBA Code:
Function CC(ColorCell As Range, DataRange As Range)

Dim Data_Range As Range
Dim Cell_Color As Long

Cell_Color = ColorCell.Interior.ColorIndex

For Each Data_Range In DataRange

If Data_Range.Interior.ColorIndex = Cell_Color Then
CC = CC + 1
End If

Next Data_Range

End Function
 
Upvote 0
You could use a function as below:
VBA Code:
Function CountRed(mnthRng As Range, mnthStr As String, personStr As String)
    Dim rCell As Range, pCell As Range, a As Long
    
    For Each rCell In mnthRng.Cells
        If rCell = mnthStr And rCell.Offset(, 1) = personStr Then
            For Each pCell In rCell.Offset(, 2).Resize(, 17).Cells
                If pCell.Interior.Color = vbRed Then
                    a = a + 1
                End If
            Next pCell
        End If
    Next rCell
    
    CountRed = a
End Function

Used in the spreadsheet as below:
PERSON.xlsm
ABCDEFGHIJKLMNOPQRSTUV
101/01/2023January
2
3JanuaryNamesSundayMondayTuesdayWednesdayThursdayFridaySaturdaySundayMondayTuesdayWednesdayThursdayFridaySaturdayMonthJanuary
4January1234567891011121314NamePerson A
5JanuaryPerson AHolidaytrainingtrainingtrainingtrainingtrainingtrainingTrainingTrainingTrainingTrainingTrainingTrainingFind Whattraining
6JanuaryPerson BHolidayHolidayOfficeOfficeOfficeofficeofficeofficeofficeofficeofficeCount15
7JanuaryPerson CHolidayofficeofficeofficeofficeofficeofficeofficeofficeofficeRed2
8JanuaryPerson DHolidayofficeofficeofficeofficeOfficeOfficeOfficeOfficeOffice
9JanuaryPerson EHolidayHolidaytrainingtrainingtrainingtrainingtrainingtrainingtrainingtrainingtrainingtrainingtraining
10JanuarySundayMondayTuesdayWednesdayThursdayFridaySaturdaySundayMondayTuesdayWednesdayThursdayFridaySaturdaySundayMondayTuesday
11January1516171819202122232425262728293031
12JanuaryPerson AtrainingTrainingofficeofficeholidayHolidayOfficeOfficeTrainingOfficeOfficeSiteSite
13JanuaryPerson BOfficeSiteSiteSiteSiteSiteSiteSiteSiteSiteSiteSiteSiteSiteSiteOfficeSite
14JanuaryPerson CHolidayofficeofficeofficeofficeOfficeOfficeOfficeHolidayHolidayOfficeOffice
15JanuaryPerson DofficeofficeofficeofficeofficeOfficeOfficeOfficeOfficeHolidayHolidayOffice
16JanuaryPerson ETrainingTrainingTrainingTrainingofficeOfficeOfficeOfficeOfficeOfficeTrainingTrainingTraining
17
1801/02/2023February
19
20FebruaryNamesSundayMondayTuesdayWednesdayThursdayFridaySaturdaySundayMondayTuesdayWednesdayThursdayFridaySaturday
21February1234567891011121314
22FebruaryPerson AHolidaytrainingOfficeOfficetrainingtrainingtrainingTrainingTrainingTrainingTrainingTrainingTraining
23FebruaryPerson BHolidayHolidayOfficeOfficeOfficeofficeofficeofficeofficeofficeoffice
24FebruaryPerson CHolidayofficeofficeofficeofficeofficeofficeofficeofficeoffice
25FebruaryPerson DHolidayofficeofficeofficeofficeOfficeOfficeOfficeOfficeOffice
26FebruaryPerson EHolidayHolidaytrainingtrainingtrainingtrainingtrainingtrainingtrainingtrainingtrainingtrainingtraining
27FebruarySundayMondayTuesdayWednesdayThursdayFridaySaturdaySundayMondayTuesdayWednesdayThursdayFridaySaturdaySundayMondayTuesday
28February1516171819202122232425262728293031
29FebruaryPerson AtrainingTrainingofficeofficeholidayHolidayOfficeOfficeTrainingOfficeOfficeSiteSite
30FebruaryPerson BOfficeSiteSiteSiteSiteSiteSiteSiteSiteSiteSiteSiteSiteSiteSiteOfficeSite
31FebruaryPerson CHolidayofficeofficeofficeofficeOfficeOfficeOfficeHolidayHolidayOfficeOffice
32FebruaryPerson DofficeofficeofficeofficeofficeOfficeOfficeOfficeOfficeHolidayHolidayOffice
33FebruaryPerson ETrainingTrainingTrainingTrainingofficeOfficeOfficeOfficeOfficeOfficeTrainingTrainingTraining
Sheet3
Cell Formulas
RangeFormula
V6V6=IFERROR(LET( tc,TOCOL(FILTER(C3:S33,(A3:A33=V3)*(B3:B33=V4))), ROWS(FILTER(tc,tc=V5))),0)
V7V7=CountRed(A3:A33,V3,V4)
A3:A16A3=$N$1
A20:A33A20=$N$18
 
Upvote 0
You're welcome.

You should probably keep the marked solution as the post that answered the thread title question and not the follow up question. This will help people who search the forum in the future.
 
Upvote 0

Forum statistics

Threads
1,223,902
Messages
6,175,278
Members
452,629
Latest member
SahilPolekar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top