Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove rows where value is *not* in column on other sheet

I have a LibreOffice Calc file with two sheets. Sheet 2 has just one column A with lots of numbers. In sheet 1, column A of every row also holds a number. I want to remove all rows from sheet 1 that have a value in column A which does not appear anywhere in column A of sheet 2.

Filters don't seem to do the trick, as they don't have a "value must be contained in some column" operator.

Any ideas?

like image 597
Lukas Barth Avatar asked Jan 02 '16 18:01

Lukas Barth


People also ask

How do you delete a row that does not match the criteria on another sheet?

Right click to click Delete from the context menu to delete the rows which are not matching the criteria on another sheet.

How do I delete all rows containing certain data?

To delete rows that contain these cells, right-click anywhere in the data range and from the drop-down menu, choose Delete.


1 Answers

Enter the following formula in cell B1 of Sheet1:

=IF(ISNA(VLOOKUP(A1,Sheet2.A:A,1, 0)),"",A1)

Then drag to fill this formula down column B. This shows empty cells for all rows that do not occur in Sheet2.

To remove the empty rows, sort on column B (Data -> Sort). Then select and delete the empty rows (Edit -> Delete Rows).

like image 71
Jim K Avatar answered Sep 20 '22 14:09

Jim K