I have been trying to make a function so that I can use 30+ IF statements in Excel (and using several different workbooks). I have discovered how to make a function but am now having problems with the ElseIf parts, it complains there is no corresponding If. Has anyone any ideas? This whole thing is quite a stab in the dark for me so it may just be punctuation.
Public Function WHATCOLOUR(st1 As String) As String
If st1 = "*Barn*" Then WHATCOLOUR = "Red"
ElseIf st1 = "*Tree*" Then WHATCOLOUR = "Green"
ElseIf st1 = "*Road*" Then WHATCOLOUR = "Black"
ElseIf st1 = "*Sky*" Then WHATCOLOUR = "Blue"
Else: WHATCOLOUR = "No Colour"
End Function
The first column holds the text string cells and the adjacent holds the =Whatcolour(xx) function. I am trying to search for parts of text string hence the * (eg "*road*" would be true for "The long and winding road that..." and would give the corresponding cell the value "Black")
I promise that the purpose is a bit more important than the examples I have filled in!!!
Thanks!
SO
Public Function WHATCOLOUR(st1 As String) As String
If st1 = "*Barn*" Then WHATCOLOUR = "Red"
ElseIf st1 = "*Tree*" Then WHATCOLOUR = "Green"
ElseIf st1 = "*Road*" Then WHATCOLOUR = "Black"
ElseIf st1 = "*Sky*" Then WHATCOLOUR = "Blue"
Else: WHATCOLOUR = "No Colour"
End Function
The first column holds the text string cells and the adjacent holds the =Whatcolour(xx) function. I am trying to search for parts of text string hence the * (eg "*road*" would be true for "The long and winding road that..." and would give the corresponding cell the value "Black")
I promise that the purpose is a bit more important than the examples I have filled in!!!
Thanks!
SO