Sebastian Koefoed
Sebastian Koefoed

Reputation: 143

VBA function with right function

just wondering why the below code returns #NAME? instead of the actual value:

Corrected VBA function:

Function LocateSite_Function(Title As String) As String

Dim StartNumber As Long

StartNumber = Len(Title) - InStr(1, Title, "_")

LocateSite_Function = Right(Title, StartNumber)

End Function

Extra:

Function FindSite_Function2(Title As String) As String

Dim SplitTitle As Variant

SplitTitle = Split(Title, "_")

FindSite_Function2 = UBound(SplitTitle)

End Function

Upvotes: 1

Views: 308

Answers (2)

Bathsheba
Bathsheba

Reputation: 234715

This could be the bizarre manifestation of a missing reference in your project. Have a look at your project references list (Tools -> References).

You can work around this using VBA.Right, or the older Right$.

Upvotes: 1

R3uK
R3uK

Reputation: 14537

Wild guess, but it is probable that you have something else called FindSite in your scope

So change the name to FindSite_Function and try again! ;)

Upvotes: 1

Related Questions