×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Check if Sheet exists

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!!!

RE: Check if Sheet exists

Hello,

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

(OP)
But where do I specify the name of the sheet to look for?

RE: Check if Sheet exists

Hello,

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

There may be a better way, but

CODE

exists = False
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

You can use also the following function

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources