Santiago Lester Clements
New Member
- Joined
- Jul 23, 2012
- Messages
- 6
Hello,
I am working on a function that should compare a String
to a list of names. I use a While loop with an if statement checking at every line of the list whether or not the content is identical to the string in argument.
However, when I run the function step by step, when I arrive at the line where the two strings are identical, the comparison still deems them as false and the loop continues to the end of the list.
The originalName is extracted from this list so it shouldn't have any extra spaces that would make the comparison return false. I have good notions of VBA, yet I can't find the mistake I made :-/
I attach my code for this function below,
thanks in advance
I am working on a function that should compare a String
Code:
originalName
However, when I run the function step by step, when I arrive at the line where the two strings are identical, the comparison still deems them as false and the loop continues to the end of the list.
The originalName is extracted from this list so it shouldn't have any extra spaces that would make the comparison return false. I have good notions of VBA, yet I can't find the mistake I made :-/
I attach my code for this function below,
thanks in advance
Code:
Public Function TrouverNom(originalName As String) As Integer
Dim i As Integer
Sheets("3-Planning par monteurs IT").Activate
i = 7
Dim presence As Boolean
presence = False
'Looping on the list of names, firstblank3 is a module variable indicating
'the first blank cell on this particular list.
While (presence = False And i <= firstblank3)
'The error is at the line below
If Range("B" & i).Value = originalName Then
'The error is at the line above
presence = True
End If
i = i + 1
Wend
TrouverNom = i - 1
Sheets("2-Besoin chantier").Activate
End Function