[vba] exact value search
Solved/Closed
cel92
Posted messages
28
Status
Membre
-
Mimi -
Mimi -
Hello,
As a beginner in VBA,
I am looking for the value "NumUnique" among the cells "B39 to B200" using the code:
"
Set CelluleTrouvee = Range("B39:B200").Find(NumUnique, LookIn:=xlValues)
"
PROBLEM: my macro does not return the cells with a value EQUAL to the NumUnique value sought, but the cells CONTAINING NumUnique.
For example, if I search for NumUnique = 2,
the result is CelluleTrouvee.Value = 52
Do you know another function that returns a cell containing the exact searched value?
Otherwise, do you have a simple example to work around the problem?
Thank you in advance!
Céline
As a beginner in VBA,
I am looking for the value "NumUnique" among the cells "B39 to B200" using the code:
"
Set CelluleTrouvee = Range("B39:B200").Find(NumUnique, LookIn:=xlValues)
"
PROBLEM: my macro does not return the cells with a value EQUAL to the NumUnique value sought, but the cells CONTAINING NumUnique.
For example, if I search for NumUnique = 2,
the result is CelluleTrouvee.Value = 52
Do you know another function that returns a cell containing the exact searched value?
Otherwise, do you have a simple example to work around the problem?
Thank you in advance!
Céline
Configuration: Windows XP Internet Explorer 6.0
6 réponses
Hello,
The Find method has an optional argument of type variant "Lookat", with possible values being xlWhole or xlPart...
Referring back to your example, it goes like this:
Public Sub test()
Dim number As Integer
Dim foundCell As Range
Dim row As Integer
Dim col As Integer
number = 8
Set foundCell = Range("A1:A5").Find(number, lookat:=xlWhole)
If foundCell Is Nothing Then
MsgBox ("not found")
Else
row = foundCell.Row
col = foundCell.Column
MsgBox ("found: row = " & row & " , column = " & col)
End If
End Sub
The Find method has an optional argument of type variant "Lookat", with possible values being xlWhole or xlPart...
Referring back to your example, it goes like this:
Public Sub test()
Dim number As Integer
Dim foundCell As Range
Dim row As Integer
Dim col As Integer
number = 8
Set foundCell = Range("A1:A5").Find(number, lookat:=xlWhole)
If foundCell Is Nothing Then
MsgBox ("not found")
Else
row = foundCell.Row
col = foundCell.Column
MsgBox ("found: row = " & row & " , column = " & col)
End If
End Sub
hich24
Posted messages
1686
Status
Membre
753
thank you
Florian
You're welcome!
Cdric
You're welcome!
Mimi
Thank you, very useful line of code!