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

时间:2021-04-04 04:45:04

Is there any way of deleting all rows that contain a certain value from another workbook? For example, I want to remove the rows that contain:

有没有办法从另一个工作簿中删除包含某个值的所有行?例如,我想删除包含以下内容的行:

123@abc.com

234@def.com

567@hlk.com

890@kiv.com ... and so on

890@kiv.com ......等等

There are 5000 emails that need to be removed. Tried a traditional Find and Replace, this would take a while though. Any ideas?

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

EDIT: The CSV I am finding the values from has no extraneous data in it, so I can in theory select everything in that CSV as a find value.

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

1 个解决方案

#1


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

#1


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