View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
bhofsetz[_112_] bhofsetz[_112_] is offline
external usenet poster
 
Posts: 1
Default Loop until a unique worksheet name is entered


What do you mean the code 'stops' if you enter a unique name?

In testing your code I get a subscript out of range error when the
sheet does not exist.

I would suggest putting in an error handler before your comparison line
that will throw an error. Then you can create your new sheet.

Give this modification of your code a try


Code:
--------------------
Sub createworksheet()
Dim monthenddate As String
Dim monthendname As String
monthenddate = Application.InputBox("Enter month end date ex-08-31-05: ")
monthendname = Replace(monthenddate, "-", "")
If monthenddate = "" Then Exit Sub
On Error GoTo NewSheet
duped:
If monthendname = Sheets(monthendname).Name Then
monthenddate = Application.InputBox("A worksheet aready exists for " & monthendname & ", enter a different date or cancel ex-08-31-05: ")
monthendname = Replace(monthenddate, "-", "")
If monthenddate = "" Then Exit Sub
End If
If monthendname = Sheets(monthendname).Name Then GoTo duped
Exit Sub
NewSheet:
Sheets("Templet").Copy Befo=Sheets(1)
Sheets("Templet (2)").Name = monthendname
Sheets(monthendname).Range("H1") = monthenddate
End Sub
--------------------



HTH


--
bhofsetz
------------------------------------------------------------------------
bhofsetz's Profile: http://www.excelforum.com/member.php...o&userid=18807
View this thread: http://www.excelforum.com/showthread...hreadid=387346