ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Lookup String in Text (https://www.excelbanter.com/excel-programming/368241-lookup-string-text.html)

okelly

Lookup String in Text
 

Hi All

I'm trying to query a string containing a list of operating systems
types and return the operating system family to me. eg "Windows NT" is
a member of "Windows" etc.

The code below returms the correct result only when the string EXACTLY
matches the code syntax, (including whitespaces, gaps, punctuation
etc...)

What syntax do I use if the string CONTAINS the pVal? I've tried

"If pVal Like "Windows NT" Then...etc.. but it's not working..

I need something like "If pVAl contains "Windows" then Operating System
= "Windows"

Thanks
Conor




Code:
--------------------

Function OperatingSystem(pVal As String) As String

If pVal = "Windows 2000 Server SP4" Then
OperatingSystem = "Windows"

ElseIf pVal = "Windows NT" Then
OperatingSystem = "Windows"
Else
OperatingSystem = "Other"
End If

End Function




--------------------


--
okelly
------------------------------------------------------------------------
okelly's Profile: http://www.excelforum.com/member.php...o&userid=36708
View this thread: http://www.excelforum.com/showthread...hreadid=564641


Kaak[_91_]

Lookup String in Text
 

Function OperatingSystem(pVal As String) As String

If InStr(pVal, "Windows") Then
OperatingSystem = "Windows"
Else
OperatingSystem = "Other"
End if

End Functio

--
Kaa
-----------------------------------------------------------------------
Kaak's Profile: http://www.excelforum.com/member.php...nfo&userid=751
View this thread: http://www.excelforum.com/showthread.php?threadid=56464


Bob Phillips

Lookup String in Text
 
Function OperatingSystem(pVal As String) As String

If LCase(pVal) Like "*windows 2000*" Then
OperatingSystem = "Windows"

ElseIf LCase(pVal) Like "*windows nt*" Then
OperatingSystem = "Windows"
Else
OperatingSystem = "Other"
End If

End Function

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"okelly" wrote in
message ...

Hi All

I'm trying to query a string containing a list of operating systems
types and return the operating system family to me. eg "Windows NT" is
a member of "Windows" etc.

The code below returms the correct result only when the string EXACTLY
matches the code syntax, (including whitespaces, gaps, punctuation
etc...)

What syntax do I use if the string CONTAINS the pVal? I've tried

"If pVal Like "Windows NT" Then...etc.. but it's not working..

I need something like "If pVAl contains "Windows" then Operating System
= "Windows"

Thanks
Conor




Code:
--------------------

Function OperatingSystem(pVal As String) As String

If pVal = "Windows 2000 Server SP4" Then
OperatingSystem = "Windows"

ElseIf pVal = "Windows NT" Then
OperatingSystem = "Windows"
Else
OperatingSystem = "Other"
End If

End Function




--------------------


--
okelly
------------------------------------------------------------------------
okelly's Profile:

http://www.excelforum.com/member.php...o&userid=36708
View this thread: http://www.excelforum.com/showthread...hreadid=564641




okelly[_2_]

Lookup String in Text
 

cool, thanks

--
okell
-----------------------------------------------------------------------
okelly's Profile: http://www.excelforum.com/member.php...fo&userid=3670
View this thread: http://www.excelforum.com/showthread.php?threadid=56464



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

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