ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   String Comparison using Like Problem (https://www.excelbanter.com/excel-programming/371242-string-comparison-using-like-problem.html)

sbowman

String Comparison using Like Problem
 
The code below is used in a search to find a row that matches a
person's name entered into a text box on a userform. I can't understand
why my like comparison isn't working:

Dim chkRequestor As String
Dim FindRequestor As String
Dim StrRequestor As String

chkRequestor = Me.txtFindRequestor.Value
StrRequestor = "*" & UCase(chkRequestor) & "*"
Requestor = Range("c" & rowindex).Value
FindRequestor = "*" & UCase(Requestor) & "*"

If StrRequestor Like FindRequestor Then
'Do commands
end if

The strrequestor value I'm using is "*SHELLEY*" and the FindRequestor
value is "*SHELLEY BOWMAN*"...why isn't this working???

Thanks,
Shelley


sbowman

String Comparison using Like Problem
 
I forgot to add Dim Requestor as string, but it is already in my code.
Help is much appreciated!!

Shelley


Tom Ogilvy

String Comparison using Like Problem
 
Isn't your comparison backwards?

? "*SHELLEY BOWMAN*" like "*SHELLEY*"
True

works for me,

but you are doing

"*SHELLEY*" Like "*SHELLEY BOWMAN*"

testing:
? "*SHELLEY*" Like "*SHELLEY BOWMAN*"
False

If you actually want to find Shelley Bowman in Shelley, then a false result
would be correct.

--
Regards,
Tom Ogilvy


"sbowman" wrote:

I forgot to add Dim Requestor as string, but it is already in my code.
Help is much appreciated!!

Shelley



sbowman

String Comparison using Like Problem
 
Thank You!!! Due to my overworked state, I am having "technical
difficulties" today :-)

Shelley



All times are GMT +1. The time now is 03:01 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com