How to lookup data in a table based on a condition, then create a new table with the data from multiple rows of the previous table?

scotte19

New Member
Joined
Oct 7, 2022
Messages
2
Office Version
  1. 2013
Platform
  1. Windows
Hi,

I have a piece of software that creates reports for us in an excel format. See below table
This table shows us what product we have built and how many of. In the end column this is product built, when this changes to zero the product has been changed.
What I need to do is every time we see a zero in that column and the line above has a value >0 take that row of data and insert it into a new table.
There could be as many as 15 of these product changes so the new table needs to be able to insert a new line below the previous one.

As a minimum I want to insert the data shown with black marks into the new table.
Can someone point me in the right direction, don't have much excel experience.

Thanks for your help

1665131893890.png
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Assuming Date Column is A, starting from second row:
This formula won't work if you have more than 1 zeros consecutively.

Excel Formula:
=IFERROR(OFFSET(INDEX(A$2:A$1000,SMALL(IF(($G$2:$G$1000)=0,MATCH(1,1*(($G$2:$G$1000)=0),0)),ROWS($A$1:A1))),-1;0),"")

Paste this formula to first cell in your 2nd table.
This is an array formula so pressing Enter is not enough. Hit Ctrl+Shift+Enter together.
Drag right and down. Don't touch to ROWS function.
 
Last edited by a moderator:
Upvote 0
Thanks for the advice, I've pasted that in and it comes up with an error with the formula.
Unfortunately I will have more than 1 zero consecutively due to the how the data is output.
 
Upvote 0
Assuming your data is from Column A to G,
Assuming your data starts from 2nd row,
Assuming you are going to paste the formula in H2:

Excel Formula:
=IFERROR(INDEX(A:A,MATCH(INDEX($G:$G,AGGREGATE(15,6,ROW($G$3:$G$1000)/(($G$3:$G$1000=0)*($G$2:$G1000<>0)),ROWS(H$3:H3))-1),$G:$G,0)),"")

This not an array formula. You may paste and use directly. It includes consecutive zeros.
Have a nice day!
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
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