Excel VBA Programming FD 3E 1118490371
Excel VBA Programming FD 3E 1118490371
If you use lots of named cells and ranges in your workbook, you may be surprised to discover that
Excel provides no way to list the details for each name. Useful information appears in the Name
Manager dialog box, but there is no way to display this information in a manner that can be printed.
The VBA code below generates a useful report that describes the names defined in any workbook.
The report, which is created on a new worksheet, includes the following information for each name:
Name: The name.
RefersTo: The definition for the name. Usually, this will be a cell or range, but a name can also
define formula.
Cells: The number of cells contained in the named range. For named formulas, this field
displays #N/A.
Wiley, the Wiley logo, For Dummies and all related trademarks, logos, and trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates.
Scope: The scope of the name, either Workbook, or the name of the specific worksheet on which
the name is valid.
Hidden: True if the name is hidden. Hidden names are created by some add-ins (such as Solver),
and do not appear in the Name Manager dialog box.
Error: True if the name contains an erroneous reference.
Link: A hyperlink that, when clicked, activates the named range. Only names that refer to cells or
ranges include a link.
Comment: The comment for the name, if any.
Exit if no names
If ActiveWorkbook.Names.Count = 0 Then
MsgBox "The active workbook has no defined names."
Exit Sub
End If
'
'
'
Wiley, the Wiley logo, For Dummies and all related trademarks, logos, and trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates.
'
'
'Column G: Hyperlink
If Not Application.IsNA(Cells(Row, 3)) Then
ActiveSheet.Hyperlinks.Add _
Anchor:=Cells(Row, 7), _
Address:="", _
SubAddress:=n.Name, _
TextToDisplay:=n.Name
End If
Wiley, the Wiley logo, For Dummies and all related trademarks, logos, and trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates.
Convert it to a table
ActiveSheet.ListObjects.Add _
SourceType:=xlSrcRange, _
Source:=Range("A4").CurrentRegion
'
Generating a Report
Execute the GenerateNameReport procedure, and the report is generated on a new worksheet in
the active workbook. The code doesn't have to be in the workbook that contains the names for the
report.
If you find this code useful, you might want to store it in your Personal Macro Workbook,
or create an add-in.
978-1-118-49037-2
Wiley, the Wiley logo, For Dummies and all related trademarks, logos, and trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates.