- Sep 21, 2009
I'm trying to write a function to test if a cell contains a website. So far I've got:
While I'm sure I could write a half-dozen more IF statements - it seems there's a better way.
I also tried a Case statement, though I suck at syntax on those. The attempt below ALWAYS thinks there's a ".com":Help????
Function IsURL(text) Dim test As Variant Dim eml As Variant eml = InStr(text, "@") 'if not present, position = 0 test = InStr(text, ".com") If eml > 1 Then IsURL = "email" ElseIf test > 4 Then IsURL = "website" Else: IsURL = "not" End If End Function
I also tried a Case statement, though I suck at syntax on those. The attempt below ALWAYS thinks there's a ".com":
Function IsURL2(text As Variant) Dim dom As Variant 'domain If InStr(text, "@") > 1 Then Exit Function Select Case InStr(text, dom) > 1 'if not present, value = 0. searching for value >1 Case dom = ".com" IsURL2 = "web" Case dom = ".net" IsURL2 = "site" Case Else IsURL2 = "not" End Select End Function