hello
how do i determine if a sheet name "cc" exist in a workbook?.
namely if it is then do so & so if it's not then create one.
thanks
hello
how do i determine if a sheet name "cc" exist in a workbook?.
namely if it is then do so & so if it's not then create one.
thanks
moshe
[vba]
If Not SheetExists("cc") Then
Worksheets.Add.Name = "cc"
End If
'-----------------------------------------------------------------
Function SheetExists(Sh As String, _
Optional wb As Workbook) As Boolean
'-----------------------------------------------------------------
Dim oWs As Worksheet
If wb Is Nothing Then Set wb = ActiveWorkbook
On Error Resume Next
SheetExists = CBool(Not wb.Worksheets(Sh) Is Nothing)
On Error GoTo 0
End Function
[/vba]
hello
whats wrong with
[VBA]
Sub targill()
Application.ScreenUpdating = False
If Not SheetExists("cc") Then
Worksheets.Add.Name = "cc"
Exit Sub
Else
Sheets("cc").Delete
Dim newsheet
Worksheets("projects").Range("A1:C4000").Copy
Set newsheet = Worksheets.Add
newsheet.Range("A1").PasteSpecial paste:=xlValues
ActiveSheet.Name = "cc"
Application.ScreenUpdating = True
End If
End Sub
[/VBA]
moshe
Could you tell us what the problem is?
Is this what you're after ?
[VBA]Sub Test()
Dim ws As Worksheet
Application.ScreenUpdating = False
For Each ws In Worksheets
If ws.Name = "CC" Then ws.UsedRange.Clear
Next ws
On Error Resume Next
If IsError(Sheets("CC").Select) Then Sheets.Add
ActiveSheet.Name = "CC"
On Error GoTo 0
Worksheets("projects").Range("A1:C4000").Copy
Range("A1").PasteSpecial Paste:=xlValues
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub[/VBA]
I always used something like:
[VBA]On Error Resume Next
Worksheets("Main").Select
If Err <> 0 Then MsgBox "Sheet does not exist."
On Error GoTo 0
[/VBA]