Excel Export - Remove Certain Rows Only

PS_Richard

New Member
Joined
Nov 22, 2022
Messages
13
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hello all,

Apologies now that the subject is a bit vague as trying to type what I want as a summary isn't easy. I have an export that comes from a software package I am unable to edit the formatting so need to do this within Excel.

Book1.xlsx
ABCDEFGHIJ
1Product CodeProduct DescriptionCatSales OrderDue DateRequiredIn StockShortfall
2BOS-194Product Description A12Sales OrderDue DateRequiredIn StockShortfall
3BOS-194Product Description A1 - Variant 123322830/11/20221
4BOS-194Product Description A1 - Variant 123348009/01/20231
5BOS-194Product Description A1 - Variant 123348109/01/20231
6BOS-194Product Description A1 - Variant 123348209/01/20231
7BOS-194Product Description A1 - Variant 123348309/01/20231
8BOS-194Product Description A1 - Variant 223383630/11/20221
9BOS-194Product Description A1 - Variant 223384128/11/20221
10BOS-194Product Description A1 - Variant 123426205/12/20223
11BOS-194Product Description A1 - Variant 123433101/12/20221
12BOS-194Product Description A1 - Variant 123448110/11/20221
13BOS-194Product Description A12Totals120-12
14CLM-027Product Description A21Sales OrderDue DateRequiredIn StockShortfall
15CLM-027Product Description A2 - Variant 113442510/11/20223
16CLM-027Product Description A2 - Variant 213444110/11/202262
17CLM-027Product Description A2 - Variant 313451910/11/20221
18CLM-027Product Description A2 - Variant 413452510/11/202239
19CLM-027Product Description A2 - Variant 513452910/11/202210
20CLM-027Product Description A21Totals1153073N/A
21KML-030Product Description A32Sales OrderDue DateRequiredIn StockShortfall
22KML-030Product Description A3 - Variant 123322830/11/20221
23KML-030Product Description A3 - Variant 123348009/01/20231
24KML-030Product Description A3 - Variant 123348109/01/20231
25KML-030Product Description A3 - Variant 123348209/01/20231
26KML-030Product Description A3 - Variant 123348309/01/20231
27KML-030Product Description A3 - Variant 223383630/11/20221
28KML-030Product Description A3 - Variant 223384128/11/20221
29KML-030Product Description A3 - Variant 123426205/12/20223
30KML-030Product Description A3 - Variant 123433101/12/20221
31KML-030Product Description A3 - Variant 123448110/11/20221
32KML-030Product Description A32Totals120-12
Sheet1


This is an example of the dataset I'm working with but numerous amount of data (over 7000 rows) but this will vary depending on when the report was run. So this is what I am after happening. If in Column I there is a negative amount then it needs to keep that and all the previous fields that have the same product code preceding it, if it shows as N/A it needs to remove those rows.

So based on that logic with the above example it would check down column I, when it spots in I13 that the is a negative amount it will know it needs to keep all the data within B2:I13. It will then move onto the next section and will see in cell I20 that it shows as N/A, it will then need to delete cell range B14:I20 and remove those rows to then proceed to the next where before the rows were removed it would see that the next value in I32 is a negative so would keep those rows.

I hope this makes sense, I'm guessing this will most likely be a VBA script rather than dumping the data in one sheet to have it in another. Any questions you need to find out more information then please let me know. Thanks in advance for any help that can be given.

Thanks, PS_Richard
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
How about
Fluff.xlsm
ABCDEFGHIJKLMNOPQRS
1Product CodeProduct DescriptionCatSales OrderDue DateRequiredIn StockShortfallProduct CodeProduct DescriptionCatSales OrderDue DateRequiredIn StockShortfall
2BOS-194Product Description A12Sales OrderDue DateRequiredIn StockShortfallBOS-194Product Description A12Sales OrderDue DateRequiredIn StockShortfall
3BOS-194Product Description A1 - Variant 1233228448951BOS-194Product Description A1 - Variant 123322844895100
4BOS-194Product Description A1 - Variant 1233480449351BOS-194Product Description A1 - Variant 123348044935100
5BOS-194Product Description A1 - Variant 1233481449351BOS-194Product Description A1 - Variant 123348144935100
6BOS-194Product Description A1 - Variant 1233482449351BOS-194Product Description A1 - Variant 123348244935100
7BOS-194Product Description A1 - Variant 1233483449351BOS-194Product Description A1 - Variant 123348344935100
8BOS-194Product Description A1 - Variant 2233836448951BOS-194Product Description A1 - Variant 223383644895100
9BOS-194Product Description A1 - Variant 2233841448931BOS-194Product Description A1 - Variant 223384144893100
10BOS-194Product Description A1 - Variant 1234262449003BOS-194Product Description A1 - Variant 123426244900300
11BOS-194Product Description A1 - Variant 1234331448961BOS-194Product Description A1 - Variant 123433144896100
12BOS-194Product Description A1 - Variant 1234481448751BOS-194Product Description A1 - Variant 123448144875100
13BOS-194Product Description A12Totals120-12BOS-194Product Description A12Totals0120-12
14CLM-027Product Description A21Sales OrderDue DateRequiredIn StockShortfallKML-030Product Description A32Sales OrderDue DateRequiredIn StockShortfall
15CLM-027Product Description A2 - Variant 1134425448753KML-030Product Description A3 - Variant 123322844895100
16CLM-027Product Description A2 - Variant 21344414487562KML-030Product Description A3 - Variant 123348044935100
17CLM-027Product Description A2 - Variant 3134519448751KML-030Product Description A3 - Variant 123348144935100
18CLM-027Product Description A2 - Variant 41345254487539KML-030Product Description A3 - Variant 123348244935100
19CLM-027Product Description A2 - Variant 51345294487510KML-030Product Description A3 - Variant 123348344935100
20CLM-027Product Description A21Totals1153073N/AKML-030Product Description A3 - Variant 223383644895100
21KML-030Product Description A32Sales OrderDue DateRequiredIn StockShortfallKML-030Product Description A3 - Variant 223384144893100
22KML-030Product Description A3 - Variant 1233228448951KML-030Product Description A3 - Variant 123426244900300
23KML-030Product Description A3 - Variant 1233480449351KML-030Product Description A3 - Variant 123433144896100
24KML-030Product Description A3 - Variant 1233481449351KML-030Product Description A3 - Variant 123448144875100
25KML-030Product Description A3 - Variant 1233482449351KML-030Product Description A32Totals0120-12
26KML-030Product Description A3 - Variant 1233483449351
27KML-030Product Description A3 - Variant 2233836448951
28KML-030Product Description A3 - Variant 2233841448931
29KML-030Product Description A3 - Variant 1234262449003
30KML-030Product Description A3 - Variant 1234331448961
31KML-030Product Description A3 - Variant 1234481448751
32KML-030Product Description A32Totals120-12
33
Details
Cell Formulas
RangeFormula
L2:S25L2=LET(u,UNIQUE(FILTER(B2:B1000,I2:I1000="N/A")),FILTER(B2:I1000,ISNA(MATCH(B2:B1000,u,0))*(B2:B1000<>"")))
Dynamic array formulas.
 
Upvote 0
Solution
This is a job for Power Query! This is the basic table I got from your data:

Book1
ABCDEFGHIJ
1Product CodeProduct DescriptionProduct ItemCatSales OrderDue DateRequiredIn StockShortfallStock - Required
2BOS-194Product Description A1Product Description A1 - Variant 123433112/01/2022100-1
3BOS-194Product Description A1Product Description A1 - Variant 123448111/10/2022100-1
4BOS-194Product Description A1Product Description A1 - Variant 123426212/05/2022300-3
5BOS-194Product Description A1Product Description A1 - Variant 123348301/09/2023100-1
6BOS-194Product Description A1Product Description A1 - Variant 123348001/09/2023100-1
7BOS-194Product Description A1Product Description A1 - Variant 123322811/30/2022100-1
8BOS-194Product Description A1Product Description A1 - Variant 123348201/09/2023100-1
9BOS-194Product Description A1Product Description A1 - Variant 123348101/09/2023100-1
10BOS-194Product Description A1Product Description A1 - Variant 223383611/30/2022100-1
11BOS-194Product Description A1Product Description A1 - Variant 223384111/28/2022100-1
12CLM-027Product Description A2Product Description A2 - Variant 113442511/10/2022300-3
13CLM-027Product Description A2Product Description A2 - Variant 213444111/10/20226200-62
14CLM-027Product Description A2Product Description A2 - Variant 313451911/10/2022100-1
15CLM-027Product Description A2Product Description A2 - Variant 413452511/10/20223900-39
16CLM-027Product Description A2Product Description A2 - Variant 513452911/10/20221000-10
17KML-030Product Description A3Product Description A3 - Variant 123426212/05/2022300-3
18KML-030Product Description A3Product Description A3 - Variant 123348201/09/2023100-1
19KML-030Product Description A3Product Description A3 - Variant 123448111/10/2022100-1
20KML-030Product Description A3Product Description A3 - Variant 123433112/01/2022100-1
21KML-030Product Description A3Product Description A3 - Variant 123348101/09/2023100-1
22KML-030Product Description A3Product Description A3 - Variant 123348001/09/2023100-1
23KML-030Product Description A3Product Description A3 - Variant 123322811/30/2022100-1
24KML-030Product Description A3Product Description A3 - Variant 123348301/09/2023100-1
25KML-030Product Description A3Product Description A3 - Variant 223383611/30/2022100-1
26KML-030Product Description A3Product Description A3 - Variant 223384111/28/2022100-1
27Count - Total2513900-139
OrdersReport
Cell Formulas
RangeFormula
B27B27=SUBTOTAL(103,[Product Description])
G27G27=SUBTOTAL(109,[Required])
H27H27=SUBTOTAL(109,[In Stock])
I27I27=SUBTOTAL(109,[Shortfall])
J27J27=SUBTOTAL(109,[Stock - Required])


The Stock - Required column was generated in Power Query. The data provided was kind of weird and hard to interpret what it actually should be.

This is the Pivot Table for that Table:

Book1
ABCD
3Row LabelsSum of RequiredSum of In StockSum of Stock - Required
4Product Description A1120-12
5Product Description A1 - Variant 1100-10
6Product Description A1 - Variant 220-2
7Product Description A21150-115
8Product Description A2 - Variant 130-3
9Product Description A2 - Variant 2620-62
10Product Description A2 - Variant 310-1
11Product Description A2 - Variant 4390-39
12Product Description A2 - Variant 5100-10
13Product Description A3120-12
14Product Description A3 - Variant 1100-10
15Product Description A3 - Variant 220-2
16Grand Total1390-139
PT Report


Learning Power Query will seem like a daunting task, but believe me it's worth every minute and designed for just this task. Inventory management I did for over 60,000 Smartphone Users across four Carriers and 100 offices holding inventory would take a day or more to reconcile each carrier, and had I known PQ it would have taken an hour or less.

Mr. E has an excellent YouTube Playlist on the subject: Power Query. Also Mike at the YouTube Channel ExcelIsFun has a full college course complete with before and after Workbooks/Worksheets for each lesson here: Full Advanced Data Analysis & BI Class (MSPTDA). Power Query, Power Pivot, DAX, M Code, Power BI & Excel.

With Power Query, you should be able to take care of this in minutes, and if you hit a speed bump, there's always plenty of help here! Good luck.
 
Upvote 0
Thanks @jdellasala, that's something I need to be looking at more into to get better at this but with the current timing I'm trying to get a short term win and using a formula like @Fluff has described is the quicker route for me now.

@Fluff Thanks for the formula, it appears to be working as planned as it's cleaned out over 4k rows that aren't needed leaving around 1k that are. I have hit a snag as two product codes where there is a negative value have failed to come through which is strange. The product codes used are P-EPCA-027 and P-EPCA-071 yet if I take them out and do a separate test with those codes and a few others it works (odd).

As you have done this is the formula used;

Excel Formula:
=LET(QQ,UNIQUE(FILTER('Stock Cat criteria -  BOM Orde'!B:B,'Stock Cat criteria -  BOM Orde'!I:I="N/A")),FILTER('Stock Cat criteria -  BOM Orde'!B:I,ISNA(MATCH('Stock Cat criteria -  BOM Orde'!B:B,QQ,0))*('Stock Cat criteria -  BOM Orde'!B:B<>"")))

The only difference I have done is had the lookup cover the entire column as the original data may fluctuate in the number of rows depending on when the data is pulled and rather than hard coding in a limit thought this would be ok? Do you have any idea what could be causing it?

Thanks again :)
 
Upvote 0
I would advise against using whole column references as it can seriously slow your workbook down, just use a limit that is more than the number of rows of data, without going over the top.

If some codes are being removed they must have an "N/A" somewhere in col I
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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