I'm wondering if there is clean cut functionality that returns True or False if a worksheet inside a workbook exists?
It would be good, but not essential, if it's possible to do it without skipping error handling.
The only thing I've found doesn't really work:
On Error Resume Next If (Worksheets("wsName").Name <> "") Then Debug.Print "Worksheet exists!" Else Debug.Print "Worksheet doesn't exist!" End If On Error GoTo ErrHandler
What is this? With this code we can use =WorksheetExists(B3) to test any text string to see if it exists as a sheet name in the current workbook.
Select the cells you want to check for duplicates. Note: Excel can't highlight duplicates in the Values area of a PivotTable report. Click Home > Conditional Formatting > Highlight Cells Rules > Duplicate Values.
Keyboard shortcut: Press CTRL+Spacebar, on the keyboard, and then press Shift+Spacebar. Copy all the data on the sheet by pressing CTRL+C. Click the plus sign to add a new blank worksheet. Click the first cell in the new sheet and press CTRL+V to paste the data.
A version without error-handling:
Function sheetExists(sheetToFind As String) As Boolean sheetExists = False For Each sheet In Worksheets If sheetToFind = sheet.name Then sheetExists = True Exit Function End If Next sheet End Function
There's no built-in function for this.
Function SheetExists(SheetName As String, Optional wb As Excel.Workbook) Dim s As Excel.Worksheet If wb Is Nothing Then Set wb = ThisWorkbook On Error Resume Next Set s = wb.Sheets(SheetName) On Error GoTo 0 SheetExists = Not s Is Nothing End Function
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With