Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
TOM TOM is offline
external usenet poster
 
Posts: 47
Default check and/or create sheet "xxx"

Hi,

I want to check if there is a sheet named "xxx".
If there is not I want to create sheet "xxx", if there
is : nothing has to be done

How can I do this in a Marco ?

Thx
Tom
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default check and/or create sheet "xxx"

Hi !

The foloowing code tries to activate sheet "xxx". If it does not axist an
error is returned (Err.Number < 0) and a new sheet is added after the last
sheet and renamed to "xxx"

Sub CheckSheet()


On Error Resume Next
Sheets("xxx").Activate
If Err.Number < 0 Then
Worksheets.Add after:=Worksheets(Worksheets.Count)
ActiveSheet.Name = "xxx"
End If

End Sub

Good Luck


"Tom" wrote in message
...
Hi,

I want to check if there is a sheet named "xxx".
If there is not I want to create sheet "xxx", if there
is : nothing has to be done

How can I do this in a Marco ?

Thx
Tom



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default check and/or create sheet "xxx"

Tom,

Dim myName As String

On Error GoTo MakeSheet
myName = Worksheets("xxx").Name
GoTo AlreadyThere

MakeSheet:
Worksheets.Add.Name = "xxx"
MsgBox "I added that sheet"

AlreadyThe
'Other Code

HTH,
Bernie
MS Excel MVP

"Tom" wrote in message
...
Hi,

I want to check if there is a sheet named "xxx".
If there is not I want to create sheet "xxx", if there
is : nothing has to be done

How can I do this in a Marco ?

Thx
Tom



  #4   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default check and/or create sheet "xxx"

Can the error message be avoid ?
-----Original Message-----
Hi !

The foloowing code tries to activate sheet "xxx". If it

does not axist an
error is returned (Err.Number < 0) and a new sheet is

added after the last
sheet and renamed to "xxx"

Sub CheckSheet()


On Error Resume Next
Sheets("xxx").Activate
If Err.Number < 0 Then
Worksheets.Add after:=Worksheets(Worksheets.Count)
ActiveSheet.Name = "xxx"
End If

End Sub

Good Luck


"Tom" wrote in

message
...
Hi,

I want to check if there is a sheet named "xxx".
If there is not I want to create sheet "xxx", if there
is : nothing has to be done

How can I do this in a Marco ?

Thx
Tom



.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default check and/or create sheet "xxx"

What do you mean ?
You don't get an error message using this code.

If you don't want to use the error object, you could also use the following
code:

Sub CheckSheet2()

Dim sh As Worksheet
Dim Fnd As Boolean

Fnd = False

For Each sh In ActiveWorkbook.Sheets
If sh.Name = "xxx" Then Fnd = True
Debug.Print sh.Name
Next sh

If Fnd = False Then
Worksheets.Add after:=Worksheets(Worksheets.Count)
ActiveSheet.Name = "xxx"
End If

End Sub

Good Luck



wrote in message
...
Can the error message be avoid ?
-----Original Message-----
Hi !

The foloowing code tries to activate sheet "xxx". If it

does not axist an
error is returned (Err.Number < 0) and a new sheet is

added after the last
sheet and renamed to "xxx"

Sub CheckSheet()


On Error Resume Next
Sheets("xxx").Activate
If Err.Number < 0 Then
Worksheets.Add after:=Worksheets(Worksheets.Count)
ActiveSheet.Name = "xxx"
End If

End Sub

Good Luck


"Tom" wrote in

message
...
Hi,

I want to check if there is a sheet named "xxx".
If there is not I want to create sheet "xxx", if there
is : nothing has to be done

How can I do this in a Marco ?

Thx
Tom



.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create Pivot Table Data with Column "Sum" rather than "count" defa Johnny_99[_2_] Excel Discussion (Misc queries) 2 January 2nd 10 03:25 PM
Check if cells contain the word "Thailand", return "TRUE" ali Excel Worksheet Functions 7 September 14th 07 09:53 AM
How can I check the "P" or "A" in the attendance sheet Capricorn Excel Worksheet Functions 1 June 8th 06 12:00 PM
create links to check boxes marked "good" fair"and "bad" pjb Excel Worksheet Functions 3 April 20th 06 02:17 AM
create a "check" macro Greg Liber Excel Programming 10 February 18th 04 04:03 AM


All times are GMT +1. The time now is 10:18 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"