Last active
August 16, 2019 07:22
-
-
Save eltioska/e716c2bfe43df9a5df3b13a9f4a720ef to your computer and use it in GitHub Desktop.
check if named range exists #excel #vba
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' 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