LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 110
Default Name Sheets in Series

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Line charting the same series using data from multiple sheets? Aaron Excel Discussion (Misc queries) 1 April 29th 10 10:10 PM
how do I fill series on different sheets Wayne Palmer Excel Worksheet Functions 2 October 6th 09 03:40 PM
Skip Rows in Fill Series and Filter to Two different sheets Benjamin Excel Worksheet Functions 3 June 30th 09 12:58 AM
Series with named range on several identical sheets caroline Charts and Charting in Excel 5 January 30th 08 03:33 AM
Charting series in different sheets (summarize) uriel78 Charts and Charting in Excel 2 February 23rd 05 01:44 PM


All times are GMT +1. The time now is 03:53 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"