Mega Code Archive

 
Categories / VisualBasic Script / Excel
 

Searching for a Name

Function IsNameInWorkbook(sName As String) As Boolean          Dim s As String          Dim rng As range          Application.Volatile          On Error Resume Next          Set rng = Application.Caller          Err.clear          If rng Is Nothing Then              s = ActiveWorkbook.Names(sName).name          Else              s = rng.Parent.Parent.Names(sName).name          End If          If Err.Number = 0 Then IsNameInWorkbook = True      End Function      Sub TestName()            If IsNameInWorkbook(InputBox("What Name")) Then            MsgBox "Name exists"            Else            MsgBox "Name does not exist"            End If      End Sub