VBAmacros“查找”function实际上没有find列中的值

我有一个VBAmacros,它将在一行中查找给定的值,一旦find它,就会find并select这个值(稍后我会做更多的工作,现在只是在寻找/select)。

问题是它没有find它应该的价值。 我正在查找的值“7/26/2014”位于Excel电子表格的单元格LS3中。 find它的代码如下:

With Sheets("Rota").Range("LS3") Set Rng = .Find(What:="7/26/2014", _ SearchOrder:=xlByColumns, _ SearchDirection:=xlNext, _ MatchCase:=False) If Not Rng Is Nothing Then Application.Goto Rng, True Else MsgBox "Nothing found" End If End With 

但是,无论我得到什么“找不到”的消息。 有人可以帮忙吗?

这是一个代码来search特定行中的所有单元格。

 Sub FindIt() Dim colNo As Long: colNo = 2 ' hardcoded to look in col 2 Dim ws As Worksheet: Set ws = ActiveSheet ' on the active sheet Dim rgCol As Range Set rgCol = ws.Columns(colNo) ' full col range (huge) Set rgCol = Application.Intersect(ws.UsedRange, rgCol) ' shrink to nec size Dim rgZeroCells As Range ' range to hold all the "0" cells (union of disjoint cells) Dim rgCell As Range ' single cell to iterate For Each rgCell In rgCol.Cells If Not IsError(rgCell) Then If rgCell.Value <> "7/26/2014" Then 'your search parameter If rgZeroCells Is Nothing Then Set rgZeroCells = rgCell ' found 1st one, assign Else Set rgZeroCells = Union(rgZeroCells, rgCell) ' found another, append End If End If End If Next rgCell If Not rgZeroCells Is Nothing Then ' do something with rgZeriCells that you found earlier... ' rgZeroCells.EntireRow.Delete ' ie deletes all the target rows at once End If End Sub