Find Next and Find Previous Methods

The FindNext method continues a search that was started with the Find method, returning the next cell that matches the criteria. The syntax is:


The After parameter must be specified or the search will begin at the upper-left corner of the range. Thus, FindNext is the same as Find, except that it uses all of the parameters (except After) that were set by the previous use of the Find method.

To continue the search from the last cell found, use that cell as the After argument. For instance, the following code searches for all cells in the top row that contain the value 0 and removes the value:

Dim c As Range

Dim sFirstHit As String ' Address of first hit With Rows(1)

Set c = .Find(0, LookIn:=xlValues) If Not c Is Nothing Then sFirstHit = c.Address Do

' Change cell contents c.Value = ""

' find next cell Set c = .FindNext(c) Loop While Not c Is Nothing End If End With

The FindPrevious method has the syntax:


and works just like the FindNext method, but searches backward in the range starting with the cell before the cell referred to by the Before parameter (with wrap around from the beginning of the range to the end).

0 -1

Post a comment