Check if Sheet exists
Check if Sheet exists
(OP)
Hi,
I'd like to write a macro that checks to see if a certain sheet already exists. If it doesn't I want it to create the sheet, and if it does, then move on.
HELP ME PLEASE!!!
I'd like to write a macro that checks to see if a certain sheet already exists. If it doesn't I want it to create the sheet, and if it does, then move on.
HELP ME PLEASE!!!





RE: Check if Sheet exists
Something like this perhaps?
Sub ADD_SHEET()
CURRENT_SHEET = ActiveSheet.Name
On Error Resume Next
Sheets("Sheet4").Select
Sheets.Add
Sheets(CURRENT_SHEET).Select
End Sub
----------------------------------
Hope this helps.
----------------------------------
maybe only a drafter
but the best user at this company!
RE: Check if Sheet exists
RE: Check if Sheet exists
The line
Sheets("Sheet4").select is the one that needs changing the "Sheet4" part needs to be a sheet name or a variable in the macro.
----------------------------------
Hope this helps.
----------------------------------
maybe only a drafter
but the best user at this company!
RE: Check if Sheet exists
CODE
For Each wkSheet in Thisworkbook.Worksheets
if wkSheet.Name = "Sheet4" Then
exists = True
End If
Next
If exists = False then
Thisworkbook.Sheets.Add Before:= _
Worksheets(Worksheets.Count)
ThisWorkbook.ActiveSheet.Name = "Sheet4"
End IF
RE: Check if Sheet exists
Public Function IsSheetExists(sname) As Boolean
Dim x As Object
On Error Resume Next
Set x = ActiveWorkbook.Sheets(sname)
If Err = 0 Then IsSheetExists = True _
Else IsSheetExists = False
End Function
have fun
Sandra