LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default .FindNext problem

Sorry this is a long post but I've been working on this forever!

I have been trying to develop a function using Find/FindNext to search
for text.

The code below is just the start of the development. What it tries to do
is look in a range in a single column and identify all occurrences of a
particular text string.

I started by writing a sub which works fine and identifies all the
occurrences of the string in parameter A (code copied from Chip Pearson):

(Parameter B will be use to compare to a 2nd column, C is the range to
search)
__________________________________________________ ____
Sub FactorX2(A As String, B As String, C As Range)
Dim FoundCell As Range
Dim LastCell As Range
Dim FirstAddress As String

With C
Set LastCell = .Cells(.Cells.Count)
End With

Set FoundCell = C.Find(what:=A, after:=LastCell, LookAt:=xlWhole)
If Not FoundCell Is Nothing Then
FirstAddress = FoundCell.Address
End If

Do Until FoundCell Is Nothing
Set FoundCell = C.FindNext(after:=FoundCell)
Debug.Print FoundCell.Address
If FoundCell.Address = FirstAddress Then
Exit Do
End If
Loop
End Sub
__________________________________________________ _____

I then tried to convert this to a function:

Function FactorX(A As String, B As String, C As Range) As Variant
Dim FoundCell As Range
Dim LastCell As Range
Dim FirstAddress As String

With C
Set LastCell = .Cells(.Cells.Count)
End With

Set FoundCell = C.Find(what:=A, after:=LastCell, LookAt:=xlWhole)
If Not FoundCell Is Nothing Then
FirstAddress = FoundCell.Address
End If

Do Until FoundCell Is Nothing
Set FoundCell = C.FindNext(after:=FoundCell)
Debug.Print "£$ " & FoundCell.Address
If FoundCell.Address = FirstAddress Then
Exit Do
End If
Loop
FactorX = 0
End Function
__________________________________________________ ________

The function finds the first string occurrence, but the
FindNext fails completely. Even if I place Debug.Print Statements before
End Function, nothing is printed. It is as though the
code exits as soon as it hits the FindNext.

Can anyone please shed any light on this?
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Findnext problem [email protected] Excel Programming 3 July 21st 06 09:23 PM
Find...FindNext Problem mtsark Excel Programming 4 August 19th 04 04:09 PM
FindNext problem mark kubicki Excel Programming 4 February 14th 04 02:42 AM
FindNext problem when using PasteSpecial Glyn Baker Excel Programming 1 December 6th 03 08:40 PM
problem with .FindNext Bob Cochran Excel Programming 6 October 11th 03 02:02 PM


All times are GMT +1. The time now is 07:08 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"