Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 557
Default Put number next to Sheet name

Hi all, I want macro which should add WorkSheet and then check if
there are more WorkSheets in ActiveWorkbook, and if there are more
WorkSheets then check if any of those WorkSheet got name "Data". If
there is no WorkSheet with name "Data" then put name "Data" to new
added WorkSheet but if there is a WorkSheet with name "Data" then put
name "Data(1)" of new added WorkSheet, and if there are WorkSheets
with names "Data" and "Data(1)" then put name "Data(2)" of new added
WorkSheet and so on like (3),(4).... I hope i was able to explain what
i need. Please can any friend can help
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,420
Default Put number next to Sheet name

Dim i As Long
Dim shName As String
Dim baseName As String

baseName = "Data"
shName = baseName
On Error Resume Next
Worksheets.Add
ActiveSheet.Name = shName
Do While ActiveSheet.Name < shName

i = i + 1
shName = baseName & "(" & i & ")"
ActiveSheet.Name = shName
Loop
On Error GoTo 0


--
__________________________________
HTH

Bob

"K" wrote in message
...
Hi all, I want macro which should add WorkSheet and then check if
there are more WorkSheets in ActiveWorkbook, and if there are more
WorkSheets then check if any of those WorkSheet got name "Data". If
there is no WorkSheet with name "Data" then put name "Data" to new
added WorkSheet but if there is a WorkSheet with name "Data" then put
name "Data(1)" of new added WorkSheet, and if there are WorkSheets
with names "Data" and "Data(1)" then put name "Data(2)" of new added
WorkSheet and so on like (3),(4).... I hope i was able to explain what
i need. Please can any friend can help



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 557
Default Put number next to Sheet name

On Jan 19, 11:22*am, "Bob Phillips" wrote:
Dim i As Long
Dim shName As String
Dim baseName As String

* * baseName = "Data"
* * shName = baseName
* * On Error Resume Next
* * Worksheets.Add
* * ActiveSheet.Name = shName
* * Do While ActiveSheet.Name < shName

* * * * i = i + 1
* * * * shName = baseName & "(" & i & ")"
* * * * ActiveSheet.Name = shName
* * Loop
* * On Error GoTo 0

--
__________________________________
HTH

Bob

"K" wrote in message

...



Hi all, *I want macro which should add WorkSheet and then check if
there are more WorkSheets in ActiveWorkbook, and if there are more
WorkSheets then check if any of those WorkSheet got name "Data". *If
there is no WorkSheet with name "Data" then put name "Data" to new
added WorkSheet but if there is a WorkSheet with name "Data" then put
name "Data(1)" of new added WorkSheet, and if there are WorkSheets
with names "Data" and "Data(1)" then put name "Data(2)" of new added
WorkSheet and so on like (3),(4).... I hope i was able to explain what
i need. *Please can any friend can help- Hide quoted text -


- Show quoted text -


Thanks lot Bob your code work superb
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Put number next to Sheet name

Bob answered you question, but just a bit of clarification...

and then check if
there are more WorkSheets in ActiveWorkbook,


A workbook must contains at least one worksheet and at least one sheet
must be visible. There is no such thing as a workbook without any
worksheets. Thus, the test "if there are more worksheets in
ActiveWorkbook" is unnecessary. Since the must be at least one sheet
to begin with, there will necessarily be "more worksheets" after a new
sheet is added.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Mon, 19 Jan 2009 02:52:56 -0800 (PST), K
wrote:

Hi all, I want macro which should add WorkSheet and then check if
there are more WorkSheets in ActiveWorkbook, and if there are more
WorkSheets then check if any of those WorkSheet got name "Data". If
there is no WorkSheet with name "Data" then put name "Data" to new
added WorkSheet but if there is a WorkSheet with name "Data" then put
name "Data(1)" of new added WorkSheet, and if there are WorkSheets
with names "Data" and "Data(1)" then put name "Data(2)" of new added
WorkSheet and so on like (3),(4).... I hope i was able to explain what
i need. Please can any friend can help

Reply
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
Macro to lookup a sheet, number, then display in origonal sheet abbsy3 New Users to Excel 3 November 9th 10 12:19 PM
Controlling sheet number during sheet add robotman Excel Programming 3 May 11th 07 01:36 PM
find an exact number in a different sheet and use the cell containing the number to output information [email protected] Excel Programming 4 February 18th 07 08:59 PM
Using the Indirect function with a sheet number instead of a sheet name JDB Excel Worksheet Functions 5 December 31st 05 03:03 PM
Macro, select Sheet "Number", NOT Sheet Name DAA Excel Worksheet Functions 4 November 30th 04 05:29 PM


All times are GMT +1. The time now is 05:28 AM.

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

About Us

"It's about Microsoft Excel"