![]() |
worksheet exists or not
How do I check if a worksheet exists or not before accessing it. -- skvabbili ------------------------------------------------------------------------ skvabbili's Profile: http://www.excelforum.com/member.php...o&userid=34135 View this thread: http://www.excelforum.com/showthread...hreadid=539068 |
worksheet exists or not
This function will let you know if a sheet exists...
Public Function SheetExists(SName As String, _ Optional ByVal Wb As Workbook) As Boolean 'Chip Pearson On Error Resume Next If Wb Is Nothing Then Set Wb = ThisWorkbook SheetExists = CBool(Len(Wb.Sheets(SName).Name)) End Function Use it like... if sheetexists("Sheet1") then sheets("Sheet1").Select -- HTH... Jim Thomlinson "skvabbili" wrote: How do I check if a worksheet exists or not before accessing it. -- skvabbili ------------------------------------------------------------------------ skvabbili's Profile: http://www.excelforum.com/member.php...o&userid=34135 View this thread: http://www.excelforum.com/showthread...hreadid=539068 |
worksheet exists or not
If SheetExists(sheetname) Then
' '----------------------------------------------------------------- Function SheetExists(Sh As String, _ Optional wb As Workbook) As Boolean '----------------------------------------------------------------- Dim oWs As Worksheet If wb Is Nothing Then Set wb = ActiveWorkbook On Error Resume Next SheetExists = CBool(Not wb.Worksheets(Sh) Is Nothing) On Error GoTo 0 End Function -- HTH Bob Phillips (remove xxx from email address if mailing direct) "skvabbili" wrote in message ... How do I check if a worksheet exists or not before accessing it. -- skvabbili ------------------------------------------------------------------------ skvabbili's Profile: http://www.excelforum.com/member.php...o&userid=34135 View this thread: http://www.excelforum.com/showthread...hreadid=539068 |
All times are GMT +1. The time now is 12:43 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com