Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Code to create worksheet names based on the values in the selectedrange


Is there any chance someone would know some code that allows me to
create new worksheets with the names of a selection of cells.

So, for example, if I selected the following cells:

Rice
Macaroni
Chicken
Hash Browns

I would like the macro to create four sheets by those names.

Any suggestions would be appreciated.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Code to create worksheet names based on the values in the selected range

Try some code like the following. The code tests whether a sheet already
exists with the particular name, and won't create a new sheet if that name
is already in use, but it doesn't test whether the name is valid for a new
worksheet.

Sub CreateSheetsFromList()
Dim R As Range
For Each R In Selection.Cells
If R.Text < vbNullString Then
If SheetExists(R.Text, ThisWorkbook) = False Then
With ThisWorkbook.Worksheets
.Add(after:=.Item(.Count)).Name = R.Text
End With
End If
End If
Next R
End Sub

Private Function SheetExists(SHName As String, WB As Workbook) As Boolean
On Error Resume Next
SheetExists = CBool(Len(WB.Worksheets(SHName).Name))
End Function


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




"Mike C" wrote in message
...

Is there any chance someone would know some code that allows me to
create new worksheets with the names of a selection of cells.

So, for example, if I selected the following cells:

Rice
Macaroni
Chicken
Hash Browns

I would like the macro to create four sheets by those names.

Any suggestions would be appreciated.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 171
Default Code to create worksheet names based on the values in the selected range

Here is a rough one...

Mark

Sub test()
Dim row As Long
Dim mysheetname As String
Dim myworksheet As String

myworksheet = ActiveSheet.Name

For row = 1 To 4
mysheetname = Cells(row, 1).Text
Sheets.Add
ActiveSheet.Name = mysheetname
Sheets(myworksheet).Select
Next
End Sub





"Mike C" wrote in message
...

Is there any chance someone would know some code that allows me to
create new worksheets with the names of a selection of cells.

So, for example, if I selected the following cells:

Rice
Macaroni
Chicken
Hash Browns

I would like the macro to create four sheets by those names.

Any suggestions would be appreciated.


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
using the Excel generic worksheet names instead of user-given names in code Paul Excel Discussion (Misc queries) 5 June 26th 09 08:44 PM
Use Cell Values to Create Tabs with specific names Mr. Matt Excel Programming 4 April 13th 07 02:06 AM
How dynamically create routing slip based on names in specific cel arich Excel Discussion (Misc queries) 1 August 25th 05 11:52 PM
Count unique values and create list based on these values vipa2000 Excel Worksheet Functions 7 August 5th 05 01:17 AM
Create seperate xls files with names based on cell text TroyB[_2_] Excel Programming 1 February 10th 04 08:11 AM


All times are GMT +1. The time now is 09:33 PM.

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"