2013-10-08 43 views
1

我在Excel中有大量的數據,我想擺脫包含我的「標籤」的行。查找選項允許我只有1個字/搜索,而且我有數百個字。它可能是一個宏觀或論點。我嘗試了以下論點,但它只發現1.在Excel中查找多個文本

=IF(OR(ISNUMBER(SEARCH({"word1","word2","word3"},A1,B1)))"YES","NO") 

有人幫我請。

+0

試試這個'= IF(OR(ISNUMBER(SEARCH({ 「字1」 ,「test」,「word3」},A1))),「是」,「否」) – Santosh

+1

謝謝喲你的Santosh工作! – user2859137

回答

0

enter image description here

宏運行

Option Explicit 

Sub RemoveRowsBasedOnArrayCondition() 
    Dim searchTerms As Variant 
    searchTerms = Array("tag1", "tag2", "tag3") 

    ReDim rowsToDelete(0) As String 

    Dim allRange As Range 
    Set allRange = ActiveSheet.UsedRange 

    Dim cell As Range, word As Variant 
    For Each cell In allRange 
     For Each word In searchTerms 
      If InStr(1, cell, word, vbTextCompare) Then 
       rowsToDelete(UBound(rowsToDelete)) = CStr(cell.Row) 
       ReDim Preserve rowsToDelete(UBound(rowsToDelete) + 1) 
      End If 
     Next word 
    Next cell 
    ReDim Preserve rowsToDelete(UBound(rowsToDelete) - 1) 
    RemoveDuplicate rowsToDelete 
    Dim v As Long 
    For v = UBound(rowsToDelete) To LBound(rowsToDelete) Step -1 
     Rows(rowsToDelete(v)).Delete 
    Next 
End Sub 


Sub RemoveDuplicate(ByRef StringArray() As String) 
    Dim lowBound$, UpBound&, A&, B&, cur&, tempArray() As String 
    If (Not StringArray) = True Then Exit Sub 
    lowBound = LBound(StringArray): UpBound = UBound(StringArray) 
    ReDim tempArray(lowBound To UpBound) 
    cur = lowBound: tempArray(cur) = StringArray(lowBound) 
    For A = lowBound + 1 To UpBound 
     For B = lowBound To cur 
      If LenB(tempArray(B)) = LenB(StringArray(A)) Then 
       If InStrB(1, StringArray(A), tempArray(B), vbBinaryCompare) = 1 Then Exit For 
      End If 
     Next B 
     If B > cur Then cur = B: tempArray(cur) = StringArray(A) 
    Next A 
    ReDim Preserve tempArray(lowBound To cur): StringArray = tempArray 
End Sub 

enter image description here

+0

它看起來如果我只是想選擇它們,並且只是突出顯示它。 – user2859137

+0

,謝謝你! – user2859137

+0

@ user2859137如果要突出顯示整行,則將「行(rowsToDelete(v))。刪除」改爲「行(rowsToDelete(v))。Interior.Color = RGB(255,0,0)' – 2013-10-08 15:24:57