View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Steve[_4_] Steve[_4_] is offline
external usenet poster
 
Posts: 184
Default Renaming newly added worksheets

Thanks Rick. That did the trick! Much appreciated.

On Mar 25, 4:31*pm, "Rick Rothstein \(MVP - VB\)"
wrote:
Give this a try...

Private Sub CommandButton2_Click()
* Dim Sh As Worksheet
* Dim Count As Long
* Dim NewCustomerSheetName As String
* For Each Sh In Sheets
* * If Left(Sh.Name, 12) = "New Customer" Then
* * * Count = Count + 1
* * End If
* Next
* If Count = 0 Then
* * NewCustomerSheetName = "New Customer"
* Else
* * NewCustomerSheetName = "New Customer (" & CStr(Count) & ")"
* End If
* Sheets("Customer Number").Copy Befo=Sheets(3)
* ActiveSheet.Name = NewCustomerSheetName
End Sub

Rick

"Steve" wrote in message

...



Hello. *I have a button that copies an existing worksheet and names it
"New Csutomer". *The problem is when the user pushes the button twice
the code errors out because there is already a sheet named "New
Customer". *Is there a way to append a number to the new sheets so
this does not happen? *Thanks!!


Private Sub CommandButton2_Click() 'Add new Customer Calc Sheets


Sheets("Customer Number").Copy Befo=Sheets(3)
ActiveSheet.Name = "New Customer"


End Sub- Hide quoted text -


- Show quoted text -