mehidy1437
Active Member
- Joined
- Nov 15, 2019
- Messages
- 348
- Office Version
- 365
- 2016
- 2013
- Platform
- Windows
- Mobile
- Web
Hello Guys
I'm facing an issue with searching value in excel in VBA.
When I search a value, if the value only exist in a1 then below code give me the resul a1.
But if same value exist in a1 & in any other cells like in a2 or b2, it gives me the result b2 or a2 i/o a1.
Why is this happening?
I'm facing an issue with searching value in excel in VBA.
When I search a value, if the value only exist in a1 then below code give me the resul a1.
But if same value exist in a1 & in any other cells like in a2 or b2, it gives me the result b2 or a2 i/o a1.
Why is this happening?
VBA Code:
Sub SearchValues()
Dim searchValue As Variant
Dim searchRange As Range
Dim foundCell As Range
searchValue = "Style"
Set searchRange = Range("A:Z")
Set foundCell = searchRange.Find(What:=searchValue, LookIn:=xlValues, LookAt:=xlPart, MatchCase:=False, SearchDirection:=xlNext, SearchOrder:=xlByRows, SearchFormat:=False)
If Not foundCell Is Nothing Then
MsgBox "Value found in cell " & foundCell.Address
Else
MsgBox "Value not found in the search range."
End If
End Sub