根据CSV Excel中的值查找和删除多行

时间:2014-01-02 15:21:15

标签: excel excel-vba replace vba

有没有办法从其他工作簿中删除包含特定值的所有行?例如,我想删除包含以下内容的行:

123@abc.com

234@def.com

567@hlk.com

890@kiv.com ...等等

需要删除5000封电子邮件。试过传统的查找和替换,这需要一段时间。有什么想法吗?

编辑:我发现值的CSV没有任何无关的数据,所以我理论上可以选择该CSV中的所有内容作为查找值。

1 个答案:

答案 0 :(得分:0)

Sub test()
' build a list of the values\strings to search for and count how many items are in the list
  check_list = "123@abc, 234@def, 567@hlk, 890@kiv"
  list_count = 4

' determine how many rows to check and assign to a variable
  numbs_rows = whatever you determine

' step through the rows and check for a match using "instr"; if there is a match, delete the row
  Range("A1").select    ' or where ever you want to start
  for x = 1 to list_count
     srch_trm = application.choose(x, check_list)  
     for y = 1 to numb_rows      
        if instr(1, activecell, srch_trm, vbTextCompare) > 1 then
           Selection.EntireRow.Delete
        end if
        activecell.offset(1,0).select
     next 
  next
End Sub