Smithfield
Smithfield

Reputation: 11

VBA compare StringArray() element with String

I am writing a small VBA program that needs to do two different things depending on if the first word of a string is "The" or "the". So far I have this but it is not matching them.

Sub Venues()

 Dim masterFile As Workbook
 Set masterFile = ActiveWorkbook

 Dim venueSplitArray() As String
 Dim tempString As String
 venueSplitArray() = Split(masterFile.Sheets(Week).Cells(I, "E"))
 tempString = venueSplitArray(0)

 If StrComp(tempString = "The", 1) And StrComp(tempString = "the", 1) Then
    ''''''CODE'''''
 Else
    ''''''CODE'''''
 End If

End Sub

But this isnt working for me and always returns that the strings don't match.

Upvotes: 0

Views: 719

Answers (1)

user3598756
user3598756

Reputation: 29421

if you want to accept both "The" or "the", then use:

If StrComp(tempString, "The", vbTextCompare) Then

if you want to differentiate "The" from "the", then use:

If StrComp(tempString, "The", vbBinaryCompare) Then

Upvotes: 1

Related Questions