Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA to number worksheets?

I am striving to build a VBA macro that will numeber and re-number m
worksheets by putting numbers before the name of each worksheet. (
find this easiest for referring to them in training, documenataion, an
verbal instructions, e.g. "Go to worksheet '17.Q4 Sales')

Below is what I have so far, but I need to enhance it to accomplish th
following:

If there is a period found at the within the first 5 characters of th
worksheet name, delete numbers found to LEFT of that period and replac
with appropriate sequential number.

This below works, but obviously adds another number every time it i
run. (Code may be recognized as being based someone else's code t
re-order worksheets or rename.)

Sub NumberWorksheets()

Dim iCtr As Long

For iCtr = 1 To Worksheets.Count
On Error Resume Next
Worksheets(iCtr).Name = iCtr & Worksheets(iCtr).Name
If Err.Number < 0 Then
MsgBox "Trouble with " & Worksheets(iCtr).Name
Err.Clear
End If
Next iCtr

End Sub

TI

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default VBA to number worksheets?

Here try this

Dim iCtr As Long
Dim iPos As Long

For iCtr = 1 To Worksheets.Count
On Error Resume Next
With Worksheets(iCtr)
iPos = InStr(1, .Name, ".")
If iPos 0 Then
.Name = iCtr & "." & Right(.Name, Len(.Name) - iPos)
Else
.Name = iCtr & "." & .Name
End If
If Err.Number < 0 Then
MsgBox "Trouble with " & Worksheets(iCtr).Name
Err.Clear
End If
End With
Next iCtr


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"wennerberg " wrote in message
...
I am striving to build a VBA macro that will numeber and re-number my
worksheets by putting numbers before the name of each worksheet. (I
find this easiest for referring to them in training, documenataion, and
verbal instructions, e.g. "Go to worksheet '17.Q4 Sales')

Below is what I have so far, but I need to enhance it to accomplish the
following:

If there is a period found at the within the first 5 characters of the
worksheet name, delete numbers found to LEFT of that period and replace
with appropriate sequential number.

This below works, but obviously adds another number every time it is
run. (Code may be recognized as being based someone else's code to
re-order worksheets or rename.)

Sub NumberWorksheets()

Dim iCtr As Long

For iCtr = 1 To Worksheets.Count
On Error Resume Next
Worksheets(iCtr).Name = iCtr & Worksheets(iCtr).Name
If Err.Number < 0 Then
MsgBox "Trouble with " & Worksheets(iCtr).Name
Err.Clear
End If
Next iCtr

End Sub

TIA


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA to number worksheets?

Thans for the help on this! You can imagine what it was like to kee
re-numbering my 30 worksheets as I re-arrenged them or inserted ne
ones

--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default VBA to number worksheets?

It's what computers are for.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"wennerberg " wrote in message
...
Thans for the help on this! You can imagine what it was like to keep
re-numbering my 30 worksheets as I re-arrenged them or inserted new
ones!


---
Message posted from http://www.ExcelForum.com/



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
number of worksheets Neia Excel Discussion (Misc queries) 6 December 4th 09 07:12 PM
Number of worksheets Gilly B[_2_] Excel Discussion (Misc queries) 3 January 3rd 09 12:40 PM
maximum number of worksheets Shooter Excel Worksheet Functions 8 July 1st 06 06:38 AM
Number of worksheets Mark Excel Discussion (Misc queries) 1 January 18th 05 10:05 AM
Default number of worksheets Nitin[_2_] Excel Programming 2 October 9th 03 09:04 PM


All times are GMT +1. The time now is 06:07 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"