|
|
|
|
|
|
Excel
|
Function to check for Chart sheet existence
|
|
Ease of Use
|
Easy
|
Version tested with
|
2002, 2003
|
Submitted by:
|
Zack Barresse
|
Description:
|
This function will return either True or False depending if the name specified belongs to a Chart sheet name or another type of sheet name. Can be used in a VBA routine or as a standard worksheet function.
|
Discussion:
|
When running code, sometimes you have the need to deal with Chart sheets. These inherently have different properties associated with them. They can be a little more tricky and involved. Usually it's good to know right away if you are dealing with a chart (for things like looping through all sheets in a workbook). This User Defined Function will give you that ability to test any sheet name and see if it is a Chart sheet or a regular worksheet.
|
Code:
|
instructions for use
|
Option Explicit
Public Function IsChart(cName As String) As Boolean
Dim tmpChart As Chart
On Error Resume Next
Set tmpChart = Charts(cName)
On Error Goto 0
IsChart = IIf(tmpChart Is Nothing, False, True)
End Function
|
How to use:
|
- Copy above code.
- In Excel press Alt + F11 to enter the Visual Basic Editor (VBE).
- Press Ctrl + R to show the Project Explorer.
- Right-click desired file on left (in bold).
- Choose Insert -> Module.
- Paste code into the right pane.
- Press Alt + Q to close the VBE.
- Save workbook before any other changes.
- Call Function as either 1) a worksheet function, or 2) within a VBA routine.
|
Test the code:
|
- From an existing workbook, save first.
- Select an empty cell.
- Type =IsChart("Chart1")
- A FALSE return will be given for everything except a Chart sheet.
|
Sample File:
|
IsChartEx.zip 9.04KB
|
Approved by mdmackillop
|
This entry has been viewed 167 times.
|
|