alpeshjain
New Member
- Joined
- Oct 5, 2017
- Messages
- 7
Hi,
I am using a custom function in VBA to check whether a range contains a particular value or not and it works fine. Here is the code -
Now the problem I am facing is, the range from where I need to search the values can contains leading/trailing spaces and I want to ignore those leading/trailing spaces while searching for the values. I can take rid this from the value being searched but have no clue of how to ignore/remove these spaces from range being searched.
PS : I am not looking for a for a loop to go cell by cell and trim the range values. I am sure that must be a more elegant solution to this.
Thanks
I am using a custom function in VBA to check whether a range contains a particular value or not and it works fine. Here is the code -
Code:
Function searchValue(fromSheet As Worksheet, value As String, col As String) As Integer Set findrange = fromSheet.Range(col).Find(What:=Trim(value), LookIn:=xlFormulas, lookat:=xlWhole)
If findrange Is Nothing Then
searchValue = 0
Else
searchValue = findrange.Row
End If
End Function
Now the problem I am facing is, the range from where I need to search the values can contains leading/trailing spaces and I want to ignore those leading/trailing spaces while searching for the values. I can take rid this from the value being searched but have no clue of how to ignore/remove these spaces from range being searched.
PS : I am not looking for a for a loop to go cell by cell and trim the range values. I am sure that must be a more elegant solution to this.
Thanks