View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Ron de Bruin Ron de Bruin is offline
external usenet poster
 
Posts: 11,123
Default Test if sheet exits, create with name if not

Oops

Use this

Sheets.Add.Name = HOTSHEET


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Ron de Bruin" wrote in message ...
Hi Bram

Copy the function and the macro in a normal module

Function SheetExists(sname As String, _
Optional ByVal WB As Workbook) As Boolean
'Chip Pearson
On Error Resume Next
If WB Is Nothing Then Set WB = ThisWorkbook
SheetExists = CBool(Len(WB.Sheets(sname).Name))
End Function

Sub Test()
Dim HOTSHEET As String
HOTSHEET = "test"
If SheetExists(HOTSHEET) = False Then
Sheets.Add.Name = "test"
Else
'do nothing
End If
End Sub




--
Regards Ron de Bruin
http://www.rondebruin.nl


"bramweisman" wrote in message ...

I have some code that successfully imports data into worksheets. I have
a variable HOTSHEET that contains the text string from a certain cell.
How can I test to see if this sheet exits, and if not create one with
the proper name. I saw Tom Oglvy's response to Steph on a similar
subject but couldn't really make sense of it in this context.


--
bramweisman
------------------------------------------------------------------------
bramweisman's Profile: http://www.excelforum.com/member.php...fo&userid=1746
View this thread: http://www.excelforum.com/showthread...hreadid=271289