Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 136
Default Sheet Order _ Numbering

Hello All.
it is my understanding that Excel calls an spreadsheet file (*.xls,
*.xlsx) a Workbook and the tabs within are called Worksheet. Looking
at the VB editor I can see the tabs are ordered as Sheetx(name of the
tab).

Here is my question. is there a way to rename the Sheetx to numbers
starting from 1 to what ever number of exiting tabs. this way once I
get a file regardless of what the user has done I can assure that the
tabs are ordered from 1 to x. then it would be easier to reference
the tabs by numbers knowing they will be there.

So essentially I am numbering the tabs starting from 1.

Ardy
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 587
Default Sheet Order _ Numbering

hi Ardy,

Dim wk As Workbook, i As Integer
Set wk = ActiveWorkbook
For i = 1 To wk.Sheets.Count
wk.Sheets(i).Name = i
Next


--
isabelle



Le 2011-12-13 11:51, Ardy a écrit :
Hello All.
it is my understanding that Excel calls an spreadsheet file (*.xls,
*.xlsx) a Workbook and the tabs within are called Worksheet. Looking
at the VB editor I can see the tabs are ordered as Sheetx(name of the
tab).

Here is my question. is there a way to rename the Sheetx to numbers
starting from 1 to what ever number of exiting tabs. this way once I
get a file regardless of what the user has done I can assure that the
tabs are ordered from 1 to x. then it would be easier to reference
the tabs by numbers knowing they will be there.

So essentially I am numbering the tabs starting from 1.

Ardy

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 136
Default Sheet Order _ Numbering

On Dec 13, 9:00*am, isabelle wrote:
hi Ardy,

Dim wk As Workbook, i As Integer
Set wk = ActiveWorkbook
For i = 1 To wk.Sheets.Count
wk.Sheets(i).Name = i
Next

--
isabelle

Le 2011-12-13 11:51, Ardy a écrit :







Hello All.
it is my understanding that Excel calls an spreadsheet file (*.xls,
*.xlsx) a Workbook and the tabs within are called Worksheet. *Looking
at the VB editor I can see the tabs are ordered as Sheetx(name of the
tab).


Here is my question. is there a way to rename the Sheetx to numbers
starting from 1 to what ever number of exiting tabs. * this way once I
get a file regardless of what the user has done I can assure that the
tabs are ordered from 1 to x. *then it would be easier to reference
the tabs by numbers knowing they will be there.


So essentially I am numbering the tabs starting from 1.


Ardy


Isabelle:
Thanks for your Quick Reply......

The code is changing the name of the tab not the pre-assigned name by
the program.

Before executing your code

Sheet2(Name 1)
Sheet3(Name 2)
Sheet4(Name 3)

After executing your code

Sheet2(1)
Sheet3(2)
Sheet4(3)

Could it be possible to do.....

Sheet1(name 1)
Sheet2(name 2)
Sheet3(name 3)

Ardy

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Sheet Order _ Numbering

Ardy presented the following explanation :
Hello All.
it is my understanding that Excel calls an spreadsheet file (*.xls,
*.xlsx) a Workbook and the tabs within are called Worksheet. Looking
at the VB editor I can see the tabs are ordered as Sheetx(name of the
tab).

Here is my question. is there a way to rename the Sheetx to numbers
starting from 1 to what ever number of exiting tabs. this way once I
get a file regardless of what the user has done I can assure that the
tabs are ordered from 1 to x. then it would be easier to reference
the tabs by numbers knowing they will be there.

So essentially I am numbering the tabs starting from 1.

Ardy


The problem you're going to run into here is duplication of existing
'codenames'. (CodeName IS what you're talking about!)

What I do is assign codenames to worksheets of a project and I use
those for selection regardless of what tabname the user assigns. I use
a custom function to get the tabname on the fly. Here's the function...

Function Get_SheetTabName(CodeName As String, Optional Wkb As Workbook)
As String
Dim Wks As Worksheet
If Wkb Is Nothing Then Set Wkb = ActiveWorkbook
For Each Wks In Wkb.Worksheets
If Wks.CodeName = CodeName Then Get_SheetTabName = Wks.Name: Exit
Function
Next
End Function

The way I assign codenames to project worksheets is as follows:

wksExpenses tabname="Expenses"
wksIncome tabname="Income"
wksSummary tabname="Summary"
wksTaxes tabname="Taxes"

...but user can change the tabname to whatever they want and I still get
the correct sheet via code as follows:

<air code
Dim wks As Worksheet
For Each wks In ActiveWorkbook.Worksheets
Sheets(Get_SheetTabName(wks.CodeName)).Protect
Next 'wks

It makes no sense to me to apply numbering to sheets since they already
have an index in the Worksheets collection. IOW, Sheet1 is #1, Sheet2
is #2, and so on. (assuming no sheets deleted) I suppose you could
rename them wks1, wks2, and so forth but why not give them meaningful
names that reflect their use in your projects? <IMO

Example:
Dim wksSource As Worksheet
Set wksSource = Sheets(Get_SheetTabName("wksSummary", ThisWorkbook))

HTH

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 587
Default Sheet Order _ Numbering

hi,

Sub Macro1()
For Each ws In ActiveWorkbook.Worksheets
i = i + 1
On Error Resume Next
ws.Parent.VBProject.VBComponents(ws.CodeName).Prop erties("_CodeName") = "Sheet" & i
Sheets(i).Name = "name " & i
On Error GoTo 0
Next ws
End Sub


--
isabelle




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,522
Default Sheet Order _ Numbering

In VBE, Put cursor on sheet namef4at the top is Name... Now you may
refer to sheet1, sheet2, etc no matter where it is moved to and what
the user changed the name to.

On Dec 13, 10:51*am, Ardy wrote:
Hello All.
it is my understanding that Excel calls an spreadsheet file (*.xls,
*.xlsx) a Workbook and the tabs within are called Worksheet. *Looking
at the VB editor I can see the tabs are ordered as Sheetx(name of the
tab).

Here is my question. is there a way to rename the Sheetx to numbers
starting from 1 to what ever number of exiting tabs. * this way once I
get a file regardless of what the user has done I can assure that the
tabs are ordered from 1 to x. *then it would be easier to reference
the tabs by numbers knowing they will be there.

So essentially I am numbering the tabs starting from 1.

Ardy


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 136
Default Sheet Order _ Numbering

On Dec 13, 12:47*pm, Don Guillett wrote:
In VBE, Put cursor on sheet namef4at the top is Name... Now you may
refer to sheet1, sheet2, etc no matter where it is moved to *and what
the user changed the name to.

On Dec 13, 10:51*am, Ardy wrote:







Hello All.
it is my understanding that Excel calls an spreadsheet file (*.xls,
*.xlsx) a Workbook and the tabs within are called Worksheet. *Looking
at the VB editor I can see the tabs are ordered as Sheetx(name of the
tab).


Here is my question. is there a way to rename the Sheetx to numbers
starting from 1 to what ever number of exiting tabs. * this way once I
get a file regardless of what the user has done I can assure that the
tabs are ordered from 1 to x. *then it would be easier to reference
the tabs by numbers knowing they will be there.


So essentially I am numbering the tabs starting from 1.


Ardy


What Would I do Without this group.......

My Thanks to all. Garry I think you hit the nail on the head.
Meaningful name s are definitely a +. I think I do that. also your
assumption was correct they are numbered unless one gets deleted,
then you run into trouble. I think I have enough to peace together to
get the show running.

Thank You all.

Ardy
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Sheet Order _ Numbering

Ardy explained on 12/13/2011 :
On Dec 13, 12:47*pm, Don Guillett wrote:
In VBE, Put cursor on sheet namef4at the top is Name... Now you may
refer to sheet1, sheet2, etc no matter where it is moved to *and what
the user changed the name to.

On Dec 13, 10:51*am, Ardy wrote:







Hello All.
it is my understanding that Excel calls an spreadsheet file (*.xls,
*.xlsx) a Workbook and the tabs within are called Worksheet. *Looking
at the VB editor I can see the tabs are ordered as Sheetx(name of the
tab).


Here is my question. is there a way to rename the Sheetx to numbers
starting from 1 to what ever number of exiting tabs. * this way once I
get a file regardless of what the user has done I can assure that the
tabs are ordered from 1 to x. *then it would be easier to reference
the tabs by numbers knowing they will be there.
So essentially I am numbering the tabs starting from 1.
Ardy


What Would I do Without this group.......

My Thanks to all. Garry I think you hit the nail on the head.
Meaningful name s are definitely a +. I think I do that. also your
assumption was correct they are numbered unless one gets deleted,
then you run into trouble. I think I have enough to peace together to
get the show running.

Thank You all.

Ardy


Thanks for the feedback!
Best wishes in your endeavour...

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


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
Purchase Order Template Numbering Whosyourdata Excel Discussion (Misc queries) 2 July 4th 09 03:17 PM
numbering rows in order 1 through whatever, then changing. PO1Draco Excel Discussion (Misc queries) 1 June 21st 08 06:14 PM
Purchase order with auto numbering ceci Excel Discussion (Misc queries) 1 June 6th 08 05:54 AM
Purchase Order Template Numbering Ken Excel Discussion (Misc queries) 0 July 26th 06 08:37 PM
Numbering items from a list in order Natalie Excel Discussion (Misc queries) 8 October 30th 05 10:43 PM


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