I am attempting to modify VBA code from the following URL:
http://www.cpearson.com/excel/ImportingFixedWidth.aspx
The section of the code I want to modify is below dealing with importing selective text. The original function returned a "False" if the line contained a keyword specified in the Array function. I have reworked it so that it shows a "True" if the line contains a keyword specified in the Array function.
My only problem is that it only does it when the keyword appears in the beginning of the line, as it uses the "Left" operator in looking at line. How do I configure the function so that it returns a "True" if the keywords appears anywhere in the line? Thanks.
Private Function ImportThisLine(S As String) As Boolean
Dim N As Long
Dim NoImportWords As Variant
Dim T As String
Dim L As Long
NoImportWords = Array("AZ", "CA")
For N = LBound(NoImportWords) To UBound(NoImportWords)
T = NoImportWords(N)
L = Len(T)
If StrComp(Left(S, L), T, vbTextCompare) = 0 Then
ImportThisLine = True
Exit Function
End If
Next N
ImportThisLine = False
End Function
Bookmarks