Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Create Pivot Table Data with Column "Sum" rather than "count" defa | Excel Discussion (Misc queries) | |||
Check if cells contain the word "Thailand", return "TRUE" | Excel Worksheet Functions | |||
How can I check the "P" or "A" in the attendance sheet | Excel Worksheet Functions | |||
create links to check boxes marked "good" fair"and "bad" | Excel Worksheet Functions | |||
create a "check" macro | Excel Programming |