2016-06-09 76 views
-1

過了一段時間,因爲我已經完成了一些編程工作,並且我沒有使用簡單的excel vba宏。我有一列的數據,我需要選擇然後刪除不包含特定值的單元格。我的數據是這樣的一列:在Excel中搜索列,找到值,選擇並刪除

990ppbAu/1,2
990ppbAu/0,5
990ppbAu/0,5
990ppbAu/0,3
9900ppmZr/29,1
9900ppmZn/5,2
9900ppmZn/1
9900ppmZn/0,8
9900ppmZn/0,5
9900ppmCu/2,8

我需要刪除該值或STRI在他們中不包含「Au」的ngs。這裏是我的代碼的開始,這不是很多,可能是錯的......但我希望有人能指出我在正確的方向:

Option Explicit 

Sub SearchColumn() 
    Dim strAu As String 
    Dim rngFound, rngDelete As Range 
    strAu = "*Au*" 

    'Search Column 
    With Columns("AF") 
    'Find values without "Au" in string in column AF and delete. 
     Set rngFound = .Find(strAu, .Cells(.Cells.Count), xlValues, xlWhole) 
     If rngFound <> strAu 
     'Then select the value and delete 
     'Else move onto the next cell until end of the document 
    End With 
End Sub 

我應該注意到,一些細胞有沒有在其中,而有些具有如上所示的字符串值。我需要它貫穿整個專欄直到文檔結束。表中有大約115,000條記錄。提前致謝!

+0

是否要刪除單元格的內容或單元格本身(以便所有其他值都向上移動)? –

+0

只是單元格的內容。沒有任何其他值的移動 –

回答

1

Edited3刪除單元格內容僅

編輯2使其刪除單細胞

編輯到 「反向」 以前的過濾標準和保持細胞含有 「AU」

如果您的專欄有標題,那麼您可以使用此代碼:

Option Explicit 

Sub SearchColumnWithHeader() 
    Dim strAu As String 

    strAu = "Au" 
    With ActiveSheet 
     With .Range("AF1", .Cells(.Rows.Count, "AF").End(xlUp)) 
      .AutoFilter Field:=1, Criteria1:="<>*" & strAu & "*" 
      If Application.WorksheetFunction.Subtotal(103, .Cells) > 1 Then .Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).ClearContents 
     End With 
     .AutoFilterMode = False 
    End With 
End Sub 
+0

這非常接近,我非常感謝您的協助。它似乎是刪除整個行,我只需要刪除它自己的單元格的內容,所以它仍然是空的。我的專欄確實有一個標題。 –

+0

查看編輯答案 – user3598756

+0

明白了!我將部分代碼稱爲「EntireRow.Delete」,改爲「ClearContents」,它似乎在做這項工作。再次感謝! –