简体   繁体   中英

Excel Formula for extracting specific rows

I have a huge data set and I want to extract the rows which do not have certain keywords.

For example, let says I have the following data set (two columns):

+--------------+------------------+ 
| Nylon        |  Nylon wire      | 
| Cable        |  5mm metal cable | 
| Epoxy        |  some comment    | 
| Polyester    |  some comment    | 
+--------------+------------------+

I want to find the rows which do not contain the keywords Nylon and Epoxy (and other keywords for that matter) and put those rows in another place (ie sheet).

Thanks in advance!

Sub a()
  With Worksheets(1)
    j = 1
    For i = 1 To .UsedRange.Rows.Count
      If .Rows(i).Find(what:="Nylon") Is Nothing And .Rows(i).Find(what:="Epoxy") Is Nothing Then
        .Rows(i).Copy Destination:=Worksheets(2).Rows(j)
        j = j + 1
      End If
    Next i
  End With
End Sub
A                   | B                  | C
  --------------------  ------------------- --------     
1 Search Term ->      |  nylon           | 
2 Name                |  Description       | Found
3 Nylon               |  Nylon Wire        | TRUE
4 Cable               |  5 mm metal cable  | FALSE
5 Exoxy               |  some comment      | FALSE
6 Polyester           |  some comment      | FALSE

In the above example, I would create an AutoFilter on A2:C6 with the first row being my headers. In each cell in C3:C6 I would have a formula akin to (this is from C3):

=OR(NOT(ISERROR(SEARCH($B$1,A3))),NOT(ISERROR(SEARCH($B$1,B3))))

Now, you can use the AutoFilter tools to filter for those where Found is true.

I'll show how you can check if one string is within some other columns, returning a boolean. Then, you'll need to decide how to handle the positive cases. I believe you'll use a VLOOKUP or something like this.

Please, replace ; by ,. I'm not using English regional settings ATM.

You can combine FIND and ISERROR function to find your result. ISERROR returns a boolean, and you can combine several column checks as much as you want.

Example:

Let's say you have the test keywords in cells C1 and D1, and the range you provided above starts at A2.

Now, we can add into C2 a testing to check if the string Nylon exists within A2, that is = ISERROR(FIND(C1;$A$2)) . We also need to check if the string Nylon exists in B2, then we add the second condition: AND(ISERROR(FIND(C1;$A$2));ISERROR(FIND(C1;$B$2)))

As we're testing if the FIND function returned error or not, it means that our function will return false when the string has been found. To be easier to understand, I believe that's better to add a NOT condition in our formula, then in case the string in C1 appears in A2 or B2, our function will return TRUE:

=NOT(AND(ISERROR(FIND(C1;$A$2));ISERROR(FIND(C1;$B$2))))

Then, we copy this formula one cell to the right to test against D1 value, Epoxy.

Now, that's the result structure:

                                            Nylon       Epoxy
 Nylon          |     Nylon wire        |   TRUE    |   FALSE
 Cable          |     5mm metal cable   |   FALSE   |   FALSE
 Epoxy          |     some comment      |   FALSE   |   TRUE
 Polyester      |     some comment      |   FALSE   |   FALSE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM