Forum Discussion
Formula Fill When Inserting Row
I have one table which lists a trailer number, the section of the yard in which it is parked, and then the row inside the parking spot (TrailerList). I also have a table which will show visually where the trailer is parked based on this list (TrailerPark). I have it set to auto-populate the trailer name from TrailerList into the correct location in TrailerPark using the formula =IFERROR(INDEX(TrailerList[[Trailer]:[Trailer]],MATCH(1,(TrailerList[[Section]:[Section]]="A1")*(TrailerList[[Row]:[Row]]="1-1"),0)),""). The issue I have is I frequently need to adjust the size of a section (ex: making section "A1" 23 rows instead of 21 as shown). Currently when I add a row the new cells hold the formula from the top row, and pushes the old row 4 formula down to row 5. Is there a way to dynamically fil the formula to match its battleship grid location? Or at least keep the moved formula relevant to the row it gets moved to?
- NikolinoDEGold Contributor
To address your issue with dynamically filling formulas when inserting rows in Excel, there are a few approaches you can take to ensure that the formulas remain relevant to their new positions and reflect the correct "battleship grid" location. Here's a solution that involves using structured references and maintaining the integrity of your formulas when adjusting the size of your sections.
Solution: Using Dynamic Ranges and Structured References
Step 1: Set Up Dynamic Named Ranges
To prevent the formulas from being misaligned when you insert new rows, you can use dynamic named ranges. These will adjust automatically as rows are added or removed, keeping your formulas accurate.
1. Create Named Ranges for your Section and Row columns in the TrailerList table.
- Go to Formulas > Name Manager > New.
- Create a name like TrailerSections and define it as:
=TrailerList[Section]
- Similarly, create a name like TrailerRows:
=TrailerList[Row]
2. Create a Named Range for the Trailer column:
- Name this range TrailerNames:
=TrailerList[Trailer]
These dynamic named ranges will update automatically as you add or remove rows in your TrailerList table.
Step 2: Adjust the Formula in the TrailerPark Table
Update the formula in your TrailerPark table to use the named ranges. This will keep the formulas relevant even when rows are added or moved.
- Update the Formula in the TrailerPark table:
=IFERROR(INDEX(TrailerNames,MATCH(1,(TrailerSections="A1")*(TrailerRows="1-1"),0)),"")
This formula references the named ranges, which dynamically adjust as the size of your TrailerList table changes.
Step 3: Insert Rows Without Breaking Formulas
When you insert rows into your TrailerPark table:
- Insert the Row normally.
- Drag Down the Formula from the row above to ensure the new row has the correct formula. Because the formula uses dynamic named ranges, it will always reference the correct data in your TrailerList table.
Step 4: Alternative - Use Structured References Directly
If you prefer not to use named ranges, you can use Excel's structured references directly within your formulas, which might look like this:
=IFERROR(INDEX(TrailerList[Trailer],MATCH(1,(TrailerList[Section]="A1")*(TrailerList[Row]="1-1"),0)),"")
This method should keep the formula relevant when you insert or move rows, as long as the TrailerList table is properly structured.
Final Tips:
- Check for Relative References: Ensure that any references in your formulas are relative (e.g., A1 rather than $A$1) so that they adjust correctly when copying or moving the formula to new cells.
- Use Table Features: Excel tables automatically expand and maintain consistent formulas within columns when rows are added. If your data is not already in an Excel table, consider converting it into one.
By using dynamic named ranges and structured references, your formulas should remain accurate and relevant, even when you insert or move rows in your TrailerPark table. The text, steps and functions were created with the help of AI.
My answers are voluntary and without guarantee!
Hope this will help you.
Was the answer useful? Mark as best response and Like it!
This will help all forum participants.
- EStar995Copper Contributor
NikolinoDE I was already using structured references in my tables (see my original formula). The issue I find is that when I input a new row, the formula no longer references the correct cells in the TrailerPark table. So for example. if I input a row between the original row 3 and 4 (battleship location 2-1 or Row 2 space 1), now the row 5 (grid 3-1) still shows the trailer that should be showing in 2-1. This means I would have to go down manually to every row and update the reference to TrailerList[Row] manually.