Skip to content

Instantly share code, notes, and snippets.

@eltioska
Last active August 16, 2019 07:22
Show Gist options
  • Select an option

  • Save eltioska/e716c2bfe43df9a5df3b13a9f4a720ef to your computer and use it in GitHub Desktop.

Select an option

Save eltioska/e716c2bfe43df9a5df3b13a9f4a720ef to your computer and use it in GitHub Desktop.
check if named range exists #excel #vba
' Solution - check if named range exists
'
' rather than checking if named range exists,
' initialise a string, add all existing named ranges' names to it,
' and then check if the required named range is in the string:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim sList As String
'--INITIALISE STRING
sList = ""
'--ADD EACH NAMED RANGE TO THE STRING
For Each Item In ActiveWorkbook.Names
sList = sList + Item.Name
Next Item
'--CHECK IF THE STRING IS PRESENT IN THE LONG STRING OF NAMES
If InStr(1, sList, "varNum") Then
'
' DO STUFF HERE
'
End If
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment