Renaming newly added worksheets
Hi Jim. I added the function, but got the same result. I put the
function in Module1. Am I doing something wrong?
On Mar 25, 4:16*pm, Jim Thomlinson <James_Thomlin...@owfg-Re-Move-
This-.com wrote:
Try something like this...
Sheets("Customer Number").Copy Befo=Sheets(3)
ActiveSheet.Name = SheetName("New Customer")
'**** Add this function
Public Function SheetName(ByVal strName As String) As String
* * Dim lng As Long
* * Dim wks As Worksheet
* * On Error Resume Next
* * Set wks = Sheets(strName)
* * Do While Not wks Is Nothing
* * * * lng = lng + 1
* * * * Set wks = Nothing
* * * * Set wks = Sheets(strName & lng)
* * Loop
* * SheetName = strName & lng
End Function
--
HTH...
Jim Thomlinson
"Steve" wrote:
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 -
|