Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Lookup Multiple text in String


Hi folks
Can you provide me the correct syntax for the "AND" command below.
ie If "HP" is found in one field and "DL380" is found in another field
then this record must relate to a "HP Proliant DL380" server etc
etc...

Thanks
Conor



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


Function Server(pVal As String, pVal2 As String) As String

If InStr(pVal, "DL380") AND (pVal2, "HP") Then
Server = "HP Proliant DL380"

ElseIf InStr(pVal, "DL340") AND (pVal2, "HP") Then
Server = "HP Proliant DL340"

ElseIf InStr(pVal, "DL580") AND (pVal2, "HP") Then
Server = "HP Proliant DL580"

Else
ServerType = "Hardware Not Defined"
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=565973

  #2   Report Post  
Posted to microsoft.public.excel.programming
Les Les is offline
external usenet poster
 
Posts: 240
Default Lookup Multiple text in String

Simply repeat the function
e.g

Function Server(pVal As String, pVal2 As String) As String

If InStr(pVal, "DL380") AND InStr(pVal2, "HP") Then
Server = "HP Proliant DL380"

ElseIf InStr(pVal, "DL340") AND InStr(pVal2, "HP") Then
Server = "HP Proliant DL340"

ElseIf InStr(pVal, "DL580") AND Instr(pVal2, "HP") Then
Server = "HP Proliant DL580"

Else
ServerType = "Hardware Not Defined"
End If

End Function

--
Les Torchia-Wells


"okelly" wrote:


Hi folks
Can you provide me the correct syntax for the "AND" command below.
ie If "HP" is found in one field and "DL380" is found in another field
then this record must relate to a "HP Proliant DL380" server etc
etc...

Thanks
Conor



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


Function Server(pVal As String, pVal2 As String) As String

If InStr(pVal, "DL380") AND (pVal2, "HP") Then
Server = "HP Proliant DL380"

ElseIf InStr(pVal, "DL340") AND (pVal2, "HP") Then
Server = "HP Proliant DL340"

ElseIf InStr(pVal, "DL580") AND (pVal2, "HP") Then
Server = "HP Proliant DL580"

Else
ServerType = "Hardware Not Defined"
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=565973


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Lookup Multiple text in String


ahhh...ok. Thnx Les :-)


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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 415
Default Lookup Multiple text in String

How's this ?
Seemed easier like this, if you need to expand the range of
manufactures/models covered

Private Sub CommandButton1_Click()
MsgBox Server(" hhh DL580lklkl", "njjjjP ")
End Sub

Function Server(pVal As String, pVal2 As String) As String
Dim ServerModels As Variant
Dim i As Long
'Just a source for the array; could also be from a WS range
Const HPSeversModels As String = "DL380,DL340,DL580"
'Const IBMSeversModels As String = "IBM100,IBM200,IBM200"

'Assume failure
Server = "Hardware Not Defined"

If InStr(pVal2, "HP") 0 Then

ServerModels = Split(HPSeversModels, ",")
For i = 0 To UBound(ServerModels)
If InStr(pVal, ServerModels(i)) 0 Then Server = "HP Proliant " &
ServerModels(i)
Next
'ElseIf InStr(pVal2, "IBM") 0 Then
'And another If with IBMServerModels
End If
End Function

NickHK

"okelly" ¼¶¼g©ó¶l¥ó·s»D:okelly.2bnpmq_1154092205.4307@excel forum-nospam.com...

Hi folks
Can you provide me the correct syntax for the "AND" command below.
ie If "HP" is found in one field and "DL380" is found in another field
then this record must relate to a "HP Proliant DL380" server etc
etc...

Thanks
Conor



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


Function Server(pVal As String, pVal2 As String) As String

If InStr(pVal, "DL380") AND (pVal2, "HP") Then
Server = "HP Proliant DL380"

ElseIf InStr(pVal, "DL340") AND (pVal2, "HP") Then
Server = "HP Proliant DL340"

ElseIf InStr(pVal, "DL580") AND (pVal2, "HP") Then
Server = "HP Proliant DL580"

Else
ServerType = "Hardware Not Defined"
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=565973



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Lookup text in a string with wildcard and return a certain value Tommy Excel Worksheet Functions 4 September 25th 08 06:21 PM
lookup a value within a text string Henrik Excel Worksheet Functions 5 March 12th 08 01:10 PM
Search, find or lookup defined text in text string zzxxcc Excel Worksheet Functions 9 September 6th 07 09:37 PM
Lookup String in Text okelly Excel Programming 3 July 25th 06 12:34 PM
LOOKUP a text string created from IF statement Steve-in-austin Excel Discussion (Misc queries) 0 May 11th 06 09:10 PM


All times are GMT +1. The time now is 04:22 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"