Leading the way in Microsoft Office Development
 Home|Excel|Word|PowerPoint|Consultancy|Feedback|Contact 
 Microsoft Excel > Functions User Defined > CONTAINS< Previous | Next > 

 

CONTAINS(sText1, sText2 [,bIgnoreCase])

 
 

Returns whether a string is contained within another string.

 

 
sText1The text string containing your substring.
sText2The text string to look for.
bIgnoreCaseWhether you want to ignore the case of the text.
 

 

REMARKS

 
 

??

 

 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Option Explicit

Public Function CONTAINS(ByVal sText1 As String, _
                         ByVal sText2 As String, _
                Optional ByVal bIgnoreCase As Boolean = False) As Boolean
                
   Call Application.Volatile(True)
                
   CONTAINS = False
   If Len(sText1) = 0 Or Len(sText2) = 0 Then Exit Function
   
   If bIgnoreCase = False Then
      If UCase(sText2) Like "*" & UCase(sText1) & "*" Then
         CONTAINS = True
      End If
   Else
      If sText2 Like "*" & sText1 & "*" Then
         CONTAINS = True
      End If
   End If
End Function
   

 

Example

 
   

 Copyright © 2004-2007 Better Solutions Limited. All Rights Reserved.< Previous | Top | Next >