Need formula range to automatically expand when a new row is added to table

Mike423

New Member
Joined
Apr 21, 2023
Messages
18
Office Version
  1. 365
Platform
  1. Windows
I'm currently using the below formula to sum individual payroll values from a large table into a smaller, summary table.

=IF(D2="YTD",SUMPRODUCT((G4:BQ13)*(G3:BQ3=A6)*(F4:F13=B2)),SUMPRODUCT((G4:BQ13)*(F4:F13=B2)*(G2:BQ2=D2)*(G3:BQ3=A6)))

My question is, how can I modify this formula, so that when I drag the bottom row of the table down (it is actually a table, not just a range) to add a new row, the ranges in the formula adjust along with it to include any data entered into the new row? Picture is attached.

Thank you.
 

Attachments

  • Table Screenshot.png
    Table Screenshot.png
    86.9 KB · Views: 50
What is the name of the table? Go back to Table Design, Properties submenu and you should see the name.
 
Upvote 0

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
If you go to an empty column somewhere on the worksheet and type =Weekly_Payroll[ in the formula bar, do you see a list of column names appear as you type the [ character? Also, as you're typing =Weekly... you should see Excel offer suggestions for what you might want to type...you should see Weekly_Payroll appear in that list...do you? And if you select one of the column names, such as =Weekly_Payroll[Week 44] (don't forget to close the right side bracket ], what do you get? Try that for several of the columns...I'm still puzzled about what the column names are.
 
Upvote 0
Yes to all of the Yes/No questions. When I type a column name in brackets and hit enter, it returns the entire column from the table.
 
Upvote 0
Okay, but if you do that for several columns within a week’s group, are you sure each has the same name (column heading)? To my knowledge, that isn’t possible because it wouldn’t be possible to distinguish between those columns based on their names. In my mockup version, when I include the week number row as my table header, Excel changes the Week 44 labels to Week 44, Week 442, Week 443, etc.

Is your table structured consistently so that the same types of hours appear for each week, and in the same order? If so, then another option is to not match the week number directly, but rather use the position of the columns within your source data array to determine where specific weeks are located.
 
Upvote 0
Ignore the Week 45 in that last column, just an error I fixed earlier.
 
Upvote 0
Without being able to explore your worksheet in detail, I can't reconcile what is happening with the column names. The approach below assumes:
  1. that every week block (the group of 7 columns associated with each week) has, for the first column of each block, a column heading that might match exactly the selection in D2 (I'm not relying on column headings for the remaining columns in each week block...only the first one). A formula then extracts the 7 columns corresponding to the specified week.
  2. that every week block contains the same hour types shown in A6:A12 (necessary because 7 columns are extracted for a specified week block)
Your inputs are largely limited to the first row of the formula where you'll need to confirm that the variables defined in the LET formula are pointing to the correct range references (the syntax is variable name followed by a comma followed by the range reference, and so on, with each set also separated from the preceding one by a comma). I'm not entirely satisfied with the nested LET used inside the IF function. That portion of the formula extracts the 7 columns associated with a specified week, and considering the unusual behavior you've described with the column headings, I don't think they can be trusted...and I can't reproduce a table like the one you've described (with multiple columns headings being duplicated). So the MATCH function is used to find the first match, and then we take it and the next 6 columns. Let me know if this works for your application. You should be able to extend the table down and to the right without further attention to the formula.

The helper columns at right are used by Data Validation, for the drop down list items in B2 and D2. You may already have something implemented for that.
MrExcel_20231030_B.xlsx
ABCDEFGHIJKLMNOPQRSTUVW
1Reg Hrs40
2Employee:Emp 1Week:Week 45Column1Week 44Week 442Week 443Week 444Week 445Week 446Week 447Week 45Week 458Week 459Week 4510Week 4511Week 4512Week 4513
3Employee NameRegular HoursOvertime HoursHolidaySickVacationFloating HolidayOtherRegular HoursOvertime HoursHolidaySickVacationFloating HolidayOtherHelper Lists
4Emp 1402392YTDEmp 0
5HoursPayEmp 2321331Week 44Emp 1
6Regular Hours20300Emp 3414224Week 442Emp 2
7Overtime HoursEmp 13212Week 443Emp 3
8HolidayWeek 444
9SickEmp 0114174Week 445
10Vacation16240Week 446
11Floating HolidayWeek 447
12OtherWeek 45
13Week 458
14Week 459
15Week 4510
16Week 4511
17Week 4512
18Week 4513
Mike423
Cell Formulas
RangeFormula
D1D1=LET(HrType,A6,EmpName,B2,qryWk,D2,HrTypeLst,A6:A12,DataRng,Weekly_Payroll,HdrWkGrps,Weekly_Payroll[#Headers], EmpCol,TAKE(DataRng,,1), HdrHrType,TAKE(DataRng,1), hary, IF(qryWk="YTD", FILTER(DataRng,HdrHrType=HrType), LET(wkary,TAKE(DROP(DataRng,,MATCH(qryWk,HdrWkGrps,0)-1),,ROWS(HrTypeLst)),FILTER(wkary,TAKE(wkary,1)=HrType))), SUM(FILTER(hary,EmpCol=EmpName)))
V4:V18V4=LET(wklst,SORT(UNIQUE(DROP(Weekly_Payroll[#Headers],,1),,1)),VSTACK("YTD",TRANSPOSE(wklst)))
W4:W7W4=LET(elst,SORT(UNIQUE(TAKE(DROP(Weekly_Payroll,1),,1))),FILTER(elst,elst<>""))
Dynamic array formulas.
Cells with Data Validation
CellAllowCriteria
B2List=$W$4#
D2List=$V$4#
 
Upvote 0
Payroll Template.xlsm
ABCDEFGHIJKLMNOPQRST
1Schedule SorterYTDYTDYTDYTDYTDYTDYTDYTDYTDYTDYTD
2Employee:Employee 5Week:Week 44Week 44Week 44Week 44Week 44Week 44Week 44Week 44Week 45Week 45Week 45Week 45Week 45Week 45Week 45
3EMPLOYEE NAMEREGULAR HOURSOVERTIME HOURSHOLIDAYSICKVACATIONFLOATING HOLIDAYOTHERREGULAR HOURSOVERTIME HOURSHOLIDAYSICKVACATIONFLOATING HOLIDAYOTHER
4Hours and PayEmployee 1402.50000035.20.804000
5HoursPayEmployee 23208000040000000
6Regular Hours20$ 300.00Employee 34000000040000000
7Overtime Hours0$ -Employee 42000880028004800
8Holiday16$ 240.00Employee 5200164000200001640
9Sick4$ 60.00Employee 63600040032000080
10Vacation0$ -Employee 74330000040000000
11Floating Holiday0$ -Employee 84000000047700000
12Other0$ -Employee 94000000040000000
13Total40$ 600.00Employee 103200800036000004
14
15Time Off
16TypeUsedRemaining
17Holiday16-
18Sick4-
19Vacation0-
20Floating Holiday0-
21Other0-
Time Sheet
Cell Formulas
RangeFormula
B6B6=IF(D2="YTD",SUMPRODUCT((G4:BQ13)*(G3:BQ3=A6)*(F4:F13=B2)),SUMPRODUCT((G4:BQ13)*(F4:F13=B2)*(G2:BQ2=D2)*(G3:BQ3=A6)))
C6:C12C6=((VLOOKUP($B$2,'Employee Details'!$C$2:$D$12,2,0))*B6)
B7B7=IF(D2="YTD",SUMPRODUCT((G4:BQ13)*(G3:BQ3=A7)*(F4:F13=B2)),SUMPRODUCT((G4:BQ13)*(F4:F13=B2)*(G2:BQ2=D2)*(G3:BQ3=A7)))
B8B8=IF(D2="YTD", SUMPRODUCT((G4:BQ13)*(G3:BQ3=A8)*(F4:F13=B2)),SUMPRODUCT((G4:BQ13)*(F4:F13=B2)*(G2:BQ2=D2)*(G3:BQ3=A8)) )
B9B9=IF(D2="YTD", SUMPRODUCT((G4:BQ13)*(G3:BQ3=A9)*(F4:F13=B2)),SUMPRODUCT((G4:BQ13)*(F4:F13=B2)*(G2:BQ2=D2)*(G3:BQ3=A9)) )
B10B10=IF(D2="YTD", SUMPRODUCT((G4:BQ13)*(G3:BQ3=A10)*(F4:F13=B2)),SUMPRODUCT((G4:BQ13)*(F4:F13=B2)*(G2:BQ2=D2)*(G3:BQ3=A10)) )
B11B11=IF(D2="YTD", SUMPRODUCT((G4:BQ13)*(G3:BQ3=A11)*(F4:F13=B2)),SUMPRODUCT((G4:BQ13)*(F4:F13=B2)*(G2:BQ2=D2)*(G3:BQ3=A11)) )
B12B12=IF(D2="YTD", SUMPRODUCT((G4:BQ13)*(G3:BQ3=A12)*(F4:F13=B2)),SUMPRODUCT((G4:BQ13)*(F4:F13=B2)*(G2:BQ2=D2)*(G3:BQ3=A12)) )
B13:C13B13=SUM(B6:B12)
B17B17=IF(D2="YTD", SUMPRODUCT((G4:BQ13)*(G3:BQ3=A17)*(F4:F13=B2)),SUMPRODUCT((G4:BQ13)*(F4:F13=B2)*(G2:BQ2=D2)*(G3:BQ3=A17)) )
C17:C21C17=IF($D$2="YTD",VLOOKUP($B$2,'Employee Details'!$C$1:$I$12,3,0)-B17,"-")
B18B18=IF(D2="YTD", SUMPRODUCT((G4:BQ13)*(G3:BQ3=A18)*(F4:F13=B2)),SUMPRODUCT((G4:BQ13)*(F4:F13=B2)*(G2:BQ2=D2)*(G3:BQ3=A18)) )
B19B19=IF(D2="YTD", SUMPRODUCT((G4:BQ13)*(G3:BQ3=A19)*(F4:F13=B2)),SUMPRODUCT((G4:BQ13)*(F4:F13=B2)*(G2:BQ2=D2)*(G3:BQ3=A19)) )
B20B20=IF(D2="YTD", SUMPRODUCT((G4:BQ13)*(G3:BQ3=A20)*(F4:F13=B2)),SUMPRODUCT((G4:BQ13)*(F4:F13=B2)*(G2:BQ2=D2)*(G3:BQ3=A20)) )
B21B21=IF(D2="YTD", SUMPRODUCT((G4:BQ13)*(G3:BQ3=A21)*(F4:F13=B2)),SUMPRODUCT((G4:BQ13)*(F4:F13=B2)*(G2:BQ2=D2)*(G3:BQ3=A21)) )
Named Ranges
NameRefers ToCells
Employee_Names='Time Sheet'!$F$4:$F$13B6:B12, B17:B21
Pay_Types='Time Sheet'!$G$3:$BQ$3B6:B12, B17:B21
Table_Data='Time Sheet'!$G$4:$BQ$13B6:B12, B17:B21
Weeks='Time Sheet'!$G$2:$BQ$2B6:B12, B17:B21
Cells with Data Validation
CellAllowCriteria
B2List='Employee Details'!$C$2:$C$1048576
E17List='Employee Details'!$A$2:$A$54
D2List='Employee Details'!$A$2:$A$54
 
Upvote 0
Sorry, took me a minute to get the Excel add-in working, but in my previous post is the spreadsheet that should include the formulas so you are able to explore the spreadsheet in more detail. Let me know if this helps.
Thanks for all your help!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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