简体   繁体   中英

Excel search and delete different specific cell that does not contain search value

i have to ask that how can search the value and ! delete the differents

if i have data like this below in column ABC and in cell A1 from sheet(2) have "bbb"

what function or VBA should i use to get rid of cell in column A and B on row that not contain bbb

try using macro record but it wont work well

      A                   B                       C

aaa-1.1.1.1         aa1a1a1a1a1               remark

bbb-2.5.2.2         b2b2b2b2b2b2              remark  

ccc-3.3.3.3         c3c3c3c3c3c3              remark

bbb-1.2.2.5         b2b2b2b2b2b2              remark  

ddd-4.1.2.4         d4d4d4d4d4d4              remark

bbb-1.3.2.7         b2b2b2b2b2b2              remark  

bbb-2.2.2.2         b2b2b2b2b2b2               remark 

result should be like

    A                  B                        C
                                              remark

bbb-2.5.2.2         b2b2b2b2b2b2              remark  

                                              remark

bbb-1.2.2.5         b2b2b2b2b2b2              remark  

                                              remark

bbb-1.3.2.7         b2b2b2b2b2b2              remark  

bbb-2.2.2.2         b2b2b2b2b2b2              remark 

Thank you for every help i can get :)

Use vba

The following would stop when it gets to an empty line...

x = 1
While Cells(x, 1) <> ""
    If Left(Cells(x, 1), 3) <> "bbb" Then
        Cells(x, 1) = ""
        Cells(x, 2) = ""
    End If
    x = x + 1
Wend

If you're not looking for an automated solution (eg this is a one-and-done scenario, no programming or recording required), you could simply sort the data based on Column A 's values, then the deletion process is trivial. In short:

  1. Highlight all rows/columns in question
  2. Right click -> Sort -> Sort A to Z
  3. Select all rows above and below rows that contain bbb . This can be done by holding CTRL while making a selection.
  4. Press delete

Here's some screen shots of these steps and the result

Sort the data 在此输入图像描述

Select rows above and below bbb 在此输入图像描述

Press the Delete key (Result) 在此输入图像描述

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