Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, and 2013. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Pulling Cell Names into VBA.
by Allen Wyatt
(last updated July 13, 2013)
If you have used Excel for any length of time, you undoubtedly know that you can define names in your worksheets that refer to various cells and ranges of cells. You can even define names that refer to constants and to formulas. (The naming abilities of Excel are really quite handy.)
As you are developing macros, you may wonder if there is a way to retrieve a list of defined names within a worksheet. This is actually quite easy, if you remember that the defined names are maintained in the Names collection, which belongs to the Workbook object. With this in mind, you can use the following code to put together a variable array that consists of all the names in a workbook:
Dim NamesList() Dim NumNames As Integer Dim x As Integer NumNames = ActiveWorkbook.Names.Count ReDim NamesList(1 To NumNames) For x = 1 To NumNames NamesList(x) = ActiveWorkbook.Names(x).Name Next x
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (5676) applies to Microsoft Excel 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Excel here: Pulling Cell Names into VBA.
Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!
When you have multiple workbooks open at the same time, Excel allows you to easily switch between those workbooks. How you do ...Discover More
When you change from one worksheet to another, you may want to have Excel automatically run a macro for the worksheet you are ...Discover More
When you need to get rid of characters in the middle of a cell value, the best way to do it is through the use of macros. ...Discover More
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.