![]() |
find a string inside another string
Hi,
this piece of code give a wrong answer ? Test Dec 05 SFE NSW Base if Strcomp(Test,"Feb") = true then ? "True" Else ? "Not" True if Strcomp(Test,"ASX") = true then ? "True" Else ? "Not" Not The word 'Feb' is not in the string but it returns a true answer. If you try the word 'ASX' it returns false. WHY and how do you fix it Thanks MarkS |
find a string inside another string
Hello MarkS,
StrComp does not returns boolean. Try Code: -------------------- Debug.Print StrComp(Test, "Feb") -------------------- The above code returns -1, True stands for -1 then printed "True". In this case I would suggest you InStr function instead of StrComp function as follows. Code: -------------------- If InStr(Test, "Feb") 0 Then Debug.Print "True" Else Debug.Print "Not" End If -------------------- --- Message posted from http://www.ExcelForum.com/ |
All times are GMT +1. The time now is 11:31 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com