Home |
Search |
Today's Posts |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Dave
Thanks. I will ajuste my sampel. I do not recall where I have than number from. Older version of Excel perhaps? -- Best regards Joergen Bondesen "Dave Peterson" wrote in message ... Is there a reason you stop after 255 sheets? I don't think I've approached that number, but excel will allow more than that -- if your pc can handle it. Joergen Bondesen wrote: Hi JAC Try below, please. Option Explicit Sub newSheet() Dim ShName As String ShName = "Database" AddSheetSheetNamed ShName End Sub '---------------------------------------------------------- ' Procedure : AddSheetSheetNamed ' Date : 20060312 ' Author : Joergen Bondesen ' Modifyed by : ' Purpose : Add a new sheet and name it. If name exist ' add _Digit format 000 ' Note : '---------------------------------------------------------- ' Function AddSheetSheetNamed(ShName As String) Dim counter As Long Dim ThisWB As Workbook Dim NoofSheets As Long Dim wshExists As Worksheet Dim ShNameOK As String counter = 0 '// This WB Set ThisWB = ThisWorkbook '// New sheet in this workbook, NoofSheets = ThisWB.Sheets.Count If NoofSheets 255 Then MsgBox "You have 255 sheets, sorry.", vbCritical End End If '//Loop ShName = Left(ShName, 28) Do On Error Resume Next Set wshExists = Nothing '// Counter counter = counter + 1 ShNameOK = ShName & "_" & Format(counter, "000") Set wshExists = Sheets(ShNameOK) If wshExists Is Nothing Then _ Sheets.Add().Name = ShNameOK On Error GoTo 0 Loop Until wshExists Is Nothing Set ThisWB = Nothing Set wshExists = Nothing End Function -- Best regards Joergen Bondesen "Jac" wrote in message ... hi, I have created a MS Excel macro that can help me to insert a new sheet and named it as Database but this macro will delete the Database sheet if I run it again. So, I would like to create a MS Excel macro which could help me to name each sheet in series. For example, if previously there is a sheet already named as Database1, then the next time, I run the macro it should name the newly inserted sheet as Database2. Could anyone help? cause I have no ideal how to compare the names of sheets in a workbook. Thanking in advance -- Dave Peterson |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Line charting the same series using data from multiple sheets? | Excel Discussion (Misc queries) | |||
how do I fill series on different sheets | Excel Worksheet Functions | |||
Skip Rows in Fill Series and Filter to Two different sheets | Excel Worksheet Functions | |||
Series with named range on several identical sheets | Charts and Charting in Excel | |||
Charting series in different sheets (summarize) | Charts and Charting in Excel |