Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 151
Default Naming multiple sheets

Hi,

I have the following code which adds lots of sheets to a workbook:

Sub AddSheets()

Dim iNoSheets As Integer

Dim x As Integer

iNoSheets = Application.InputBox("How many sheets to add?", "Add Sheets",
10, , , , 1)

For x = 1 To iNoSheets

Worksheets.Add

Next x

End Sub


How do I amend it so it changes the tab name from sheet1, sheet2 etc to a
name taken from a list of branches which are in 'sheet1' of the same file?????

Thanks

Amanda
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,069
Default Naming multiple sheets

You may need to amend some of the code to account for sheets already named
but if starting from scratch this is how i would do it in my total
non-professional capacity as a VBA'er!!

In Sheet1 name the range with the Branch names in, eg Tbl_branches


JB (:

Sub AddSheets()

Dim iNoSheets As Integer
Dim x As Integer
Dim Tbl1 as range
Dim MyBranch$
Set Tbl1 = Tbl_Branches
iNoSheets = Application.InputBox("How many sheets to add?", "Add Sheets",
10, , , , 1)

For x = 1 To iNoSheets
Worksheets.Add
Sheets("sheet" & x).Name = Application.worksheetfunction.index(tbl1,x,1)

Next x

End Sub


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 151
Default Naming multiple sheets

Hi John,

Thanks for this. I don't know VBA at all!

I've run this and it keep highlighting the row 'Set Tbl_...' as a problem.
Any ideas??

Thanks

Amanda

"John" wrote:

You may need to amend some of the code to account for sheets already named
but if starting from scratch this is how i would do it in my total
non-professional capacity as a VBA'er!!

In Sheet1 name the range with the Branch names in, eg Tbl_branches


JB (:

Sub AddSheets()

Dim iNoSheets As Integer
Dim x As Integer
Dim Tbl1 as range
Dim MyBranch$
Set Tbl1 = Tbl_Branches
iNoSheets = Application.InputBox("How many sheets to add?", "Add Sheets",
10, , , , 1)

For x = 1 To iNoSheets
Worksheets.Add
Sheets("sheet" & x).Name = Application.worksheetfunction.index(tbl1,x,1)

Next x

End Sub


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
Naming sheets from a cell value Tony4X4 Excel Discussion (Misc queries) 12 September 7th 09 01:55 PM
Naming Sheets for day of the month Socks322 Excel Discussion (Misc queries) 0 November 7th 06 03:08 PM
Macro for naming sheets? Olle Svensson Excel Discussion (Misc queries) 1 August 3rd 06 03:41 PM
Naming Sheets Tabs Cgbilliar Excel Worksheet Functions 2 November 5th 04 05:21 PM


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