View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Norman Jones Norman Jones is offline
external usenet poster
 
Posts: 5,302
Default Verify if sheet name still exist

Hi Edmund,

In a standard modulr paste the following funtion:

'=============
Public Function SheetExists(SHName As String) As String
Dim blExists As Boolean
On Error Resume Next
blExists = CBool(Len(Worksheets(SHName).Name))
On Error GoTo 0

SheetExists = IIf(blExists, "Present", "Absent")

End Function
'<<=============

In Cell B2 on Sheet1, enter the formula:

=SheetExists(A2)

and copy down as far as required.

To remove the need subsequentky to update the list with newly added sheets,
try:

'=============
Private Sub Workbook_NewSheet(ByVal SH As Object)
Dim WS As Worksheet
Dim rng As Range

Set WS = Me.Sheets("Sheet1") '<<==== CHANGE
Set rng = WS.Cells(Rows.Count, "A").End(xlUp)(2)

rng.Value = SH.Name
rng.Offset(0, 1).FormulaR1C1 = "=SheetExists(RC[-1])"
End Sub
'<<=============

This latter procedure is workbook event code and should be pasted into the
workbook's ThisWorkbook module *not* a standard module or a sheet module:

Right-click the Excel icon on the worksheet
(or the icon to the left of the File menu if your workbook is maximised)
Select 'View Code' from the menu and paste the code.
Alt-F11 to return to Excel.


---
Regards,
Norman


"Edmund" wrote in message
...
I have many sheets in the workbook. The cells in Column A of Sheet1
contains
the sheet names of each worksheet in the workbook, which is filled in by
myself manually, periodically. Because I sometimes delete some sheets
without updating the records in Column A of Sheet1, I need a macro to
distinguish if the names contained in Column A of Sheet1 is still valid
ie.
sheet name is still existing among the worksheets in the workbook. It will
be
good to return the result as a remark ("present" or "absent") in Column B
of
Sheet1.

VBA rookie here.
Thanks a lot

--
Edmund
(Using Excel XP)