2016-06-09 77 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”,它似乎在做这项工作。再次感谢! –