last day (15 days later) » 

11:08 AM
0
Q: Why does Range.FindNext NOT inherit parameters?

Tim StackI have a project which requires a lot of searches to be done through various sheets, for which I use VBA's Find function together with FindNext in a Do While...Loop. It has come to my attention that the FindNext function does not inherit the parameters provided by the previous search. Thus, if ...

 
It works just fine for me
 
I don't have it specified. It does not find the search string as a substring either, as it just finds a largely different value. E.g. search string 89.0700.011.0005, but it finds 89.2360.015.0001
 
I think you are confusing between Match Case and SearchFormat? MatchCase is for strings.... differentiating between capital and lower-case letters... MatchCase (Optional Variant): True to make the search case sensitive. The default value is False.
 
Right, so technically a wrong use of parameters there. Still, it does work in getting the right cell. Does not explain why FindNext is giving wrong ranges
 
Like I mentioned, it works for me. If i search for 89.0700.011.0005, it gives me only that and not 89.2360.015.0001
I used THIS code for testing
 
11:08 AM
Very odd, almost has me thinking this is rather a system issue. I recall reading a thread by someone experiencing the same issue. FindNext didn't inherit any arguments either. SearchFormat is not what I need, simply need xlWhole.
 
Can you try the code from the link that I shared... Use it as it is shown there... Do you still see unnecessary results?
 
There are 8 pieces of code there of which the "final" one does not use FindNext
 
Hi
Sub Sample()
    Dim oRange As Range, aCell As Range, bCell As Range
    Dim ws As Worksheet
    Dim ExitLoop As Boolean
    Dim SearchString As String, FoundAt As String

    On Error GoTo Whoa

    Set ws = Worksheets("Sheet1")
    Set oRange = ws.Cells

    SearchString = "89.0700.011.0005"

    Set aCell = oRange.Find(What:=SearchString, LookIn:=xlValues, _
                LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
                MatchCase:=True, SearchFormat:=False)
This is the code that I tried. it gave me only one cell
 
Hi, I'm currently altering a piece of code in the macro so I am now unable to test. I have already replaced the FindNext with a new Find function, so give me a second while I finish writing and replace the Find function with Findnext
I don't see why the after argument is necessary with FindNext, does it not already do this?
 
It is not :)
I mean it is not necessary to specify it.
 
11:13 AM
What I figured
I mean this code is almost identical to my process, and it would appear to work perfectly fine
 
It is like Saying Msgbox Range("A1").value and Msgbox Range("A1")
 
I'll be back in a few after I rewrote the code
 
It is understood that you mean After:=
ok
 
11:25 AM
Alright, got it figured out
 
ok great
 
The MatchCase argument clearly was a poor choice, so it would find other values than the search string I specified. This would find the correct string the first try, but with the second (thus FindNext) try it would find a different string. I replaced MatchCase:=True with lookat:=xlWhole and the FindNext function returned the right range. Cheers for the help
 
you are welcome :)
Leaving the room. If you have any queries, post below the quesiton.
 

last day (15 days later) »