0

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.

3
  • It should NOT be StrComp(tempString = "The", 1), it should instead be: StrComp(tempString, "The", 1) (and you'll need to make the adjustment for both StrComp calls). Commented Aug 19, 2016 at 14:33
  • 1
    Surely your If line should be or not and? Commented Aug 19, 2016 at 14:33
  • Also, you should omit the third argument 1 or set it to 0 so that it does a case sensitive comparison, and then leave out the And.... portion of the IF statement. Commented Aug 19, 2016 at 14:35

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.