Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 410
Default VBA Help naming sheets

I am having trouble naming sheets based on a range of cells. I want a
new worksheet to be added and be named after new data in range
B7:B25. I will insert a button or somethign to run the macro, I just
need some help with the code to do it. The range is a list of names.
After I have entered names, I want to push a button and have the new
names be their own tabs.

Please help,
Jay
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9,101
Default VBA Help naming sheets


Sub addsheets()

Set sheetnames = Range("B7:B25")
For Each sht In sheetnames
Worksheets.Add after:=Sheets(Sheets.Count)
ActiveSheet.Name = sht
Next sht

End Sub

"jlclyde" wrote:

I am having trouble naming sheets based on a range of cells. I want a
new worksheet to be added and be named after new data in range
B7:B25. I will insert a button or somethign to run the macro, I just
need some help with the code to do it. The range is a list of names.
After I have entered names, I want to push a button and have the new
names be their own tabs.

Please help,
Jay

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 410
Default VBA Help naming sheets

On Nov 20, 11:01 am, Joel wrote:
Sub addsheets()

Set sheetnames = Range("B7:B25")
For Each sht In sheetnames
Worksheets.Add after:=Sheets(Sheets.Count)
ActiveSheet.Name = sht
Next sht

End Sub



"jlclyde" wrote:
I am having trouble naming sheets based on a range of cells. I want a
new worksheet to be added and be named after new data in range
B7:B25. I will insert a button or somethign to run the macro, I just
need some help with the code to do it. The range is a list of names.
After I have entered names, I want to push a button and have the new
names be their own tabs.


Please help,
Jay- Hide quoted text -


- Show quoted text -


How do you get it to stop after the last entry and not add another
blank sheet?
Jay
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9,101
Default VBA Help naming sheets

Sub addsheets()

Set sheetnames = Range("B7:B25")
For Each sht In sheetnames
if sht < "" then
Worksheets.Add after:=Sheets(Sheets.Count)
ActiveSheet.Name = sht
end
Next sht

End Sub

"jlclyde" wrote:

On Nov 20, 11:01 am, Joel wrote:
Sub addsheets()

Set sheetnames = Range("B7:B25")
For Each sht In sheetnames
Worksheets.Add after:=Sheets(Sheets.Count)
ActiveSheet.Name = sht
Next sht

End Sub



"jlclyde" wrote:
I am having trouble naming sheets based on a range of cells. I want a
new worksheet to be added and be named after new data in range
B7:B25. I will insert a button or somethign to run the macro, I just
need some help with the code to do it. The range is a list of names.
After I have entered names, I want to push a button and have the new
names be their own tabs.


Please help,
Jay- Hide quoted text -


- Show quoted text -


How do you get it to stop after the last entry and not add another
blank sheet?
Jay

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 410
Default VBA Help naming sheets

On Nov 20, 12:16 pm, Joel wrote:
Sub addsheets()

Set sheetnames = Range("B7:B25")
For Each sht In sheetnames
if sht < "" then
Worksheets.Add after:=Sheets(Sheets.Count)
ActiveSheet.Name = sht
end
Next sht

End Sub



"jlclyde" wrote:
On Nov 20, 11:01 am, Joel wrote:
Sub addsheets()


Set sheetnames = Range("B7:B25")
For Each sht In sheetnames
Worksheets.Add after:=Sheets(Sheets.Count)
ActiveSheet.Name = sht
Next sht


End Sub


"jlclyde" wrote:
I am having trouble naming sheets based on a range of cells. I want a
new worksheet to be added and be named after new data in range
B7:B25. I will insert a button or somethign to run the macro, I just
need some help with the code to do it. The range is a list of names.
After I have entered names, I want to push a button and have the new
names be their own tabs.


Please help,
Jay- Hide quoted text -


- Show quoted text -


How do you get it to stop after the last entry and not add another
blank sheet?
Jay- Hide quoted text -


- Show quoted text -


Even when you add the if after End it still is not working properly.
It adds one extra sheet and then throws an error.
Jay


  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9,101
Default VBA Help naming sheets

The code doesn't run an extra loop. It only runs through the range of cells
specified. There is some data in the last cell that it ran that cannot be
used in a sheet name. Sheet names cannot contain the following six
characters / \ ? * [ ]. The sheet name cannot be larger than 31 characters.

I can add some additional tests for bad sheetname but can you tell me which
names it doesn't like and how you want the problem fixed.

"jlclyde" wrote:

On Nov 20, 12:16 pm, Joel wrote:
Sub addsheets()

Set sheetnames = Range("B7:B25")
For Each sht In sheetnames
if sht < "" then
Worksheets.Add after:=Sheets(Sheets.Count)
ActiveSheet.Name = sht
end
Next sht

End Sub



"jlclyde" wrote:
On Nov 20, 11:01 am, Joel wrote:
Sub addsheets()


Set sheetnames = Range("B7:B25")
For Each sht In sheetnames
Worksheets.Add after:=Sheets(Sheets.Count)
ActiveSheet.Name = sht
Next sht


End Sub


"jlclyde" wrote:
I am having trouble naming sheets based on a range of cells. I want a
new worksheet to be added and be named after new data in range
B7:B25. I will insert a button or somethign to run the macro, I just
need some help with the code to do it. The range is a list of names.
After I have entered names, I want to push a button and have the new
names be their own tabs.


Please help,
Jay- Hide quoted text -


- Show quoted text -


How do you get it to stop after the last entry and not add another
blank sheet?
Jay- Hide quoted text -


- Show quoted text -


Even when you add the if after End it still is not working properly.
It adds one extra sheet and then throws an error.
Jay

  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 410
Default VBA Help naming sheets

On Nov 20, 1:39 pm, Joel wrote:
Does the sheet name already exist? Do we ned to test if the namealready
exists?

If you highlight "sht" and right click you can add it to the watch window
and see the value of sht.



"jlclyde" wrote:
On Nov 20, 1:20 pm, jlclyde wrote:
On Nov 20, 12:57 pm, Joel wrote:


The code doesn't run an extra loop. It only runs through the range of cells
specified. There is some data in the last cell that it ran that cannot be
used in a sheet name. Sheet names cannot contain the following six
characters / \ ? * [ ]. The sheet name cannot be larger than 31 characters.


I can add some additional tests for bad sheetname but can you tell me which
names it doesn't like and how you want the problem fixed.


"jlclyde" wrote:
On Nov 20, 12:16 pm, Joel wrote:
Sub addsheets()


Set sheetnames = Range("B7:B25")
For Each sht In sheetnames
if sht < "" then
Worksheets.Add after:=Sheets(Sheets.Count)
ActiveSheet.Name = sht
end
Next sht


End Sub


"jlclyde" wrote:
On Nov 20, 11:01 am, Joel wrote:
Sub addsheets()


Set sheetnames = Range("B7:B25")
For Each sht In sheetnames
Worksheets.Add after:=Sheets(Sheets.Count)
ActiveSheet.Name = sht
Next sht


End Sub


"jlclyde" wrote:
I am having trouble naming sheets based on a range of cells. I want a
new worksheet to be added and be named after new data in range
B7:B25. I will insert a button or somethign to run the macro, I just
need some help with the code to do it. The range is a list of names.
After I have entered names, I want to push a button and have the new
names be their own tabs.


Please help,
Jay- Hide quoted text -


- Show quoted text -


How do you get it to stop after the last entry and not add another
blank sheet?
Jay- Hide quoted text -


- Show quoted text -


Even when you add the if after End it still is not working properly.
It adds one extra sheet and then throws an error.
Jay- Hide quoted text -


- Show quoted text -


Joel
ActiveSheet.Name = sht (this is highlighted after I try to debug it.
It adds an extra sheet. For example if I have five names and it
currently has 2 sheets, it will add the 5 names, it will add a 6 sheet
named Sheet3 and then it will throw the error. There is nothing in
any of the other cells. I have cleared coments and deleted them
twice. Let me kow if you can think of anything to fix this.
Thanks,
Jay- Hide quoted text -


- Show quoted text -


Sub addsheets()


Set sheetnames = Range("B7", Sheet1.Range("B25").End(xlUp))
For Each sht In sheetnames
If sht < "" Then
Worksheets.Add after:=Sheets(Sheets.Count)
ActiveSheet.Name = sht
Else: Exit Sub
End If
Next sht


End Sub


This is what I changed teh code to. I thought that i would take out
any of the blank cells out of the equation.
jay- Hide quoted text -


- Show quoted text -


Here is what I have in B starting at B7
Dog
Cat
Monkey
Dog

When I run this macro

Sub addsheets()

Set sheetnames = Range("B7", Sheet1.Range("B25").End(xlUp))
For Each sht In sheetnames
If sht < "" Then
Worksheets.Add after:=Sheets(Sheets.Count)
ActiveSheet.Name = sht
Else: Exit Sub
End If
Next sht

End Sub

It adds all the right sheets and then one more. plus the other stuff
that i said. See fi maybe you can recreate my problem and tell me how
to fix it. I know that your code is close.

Thanks,
Jay
  #8   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9,101
Default VBA Help naming sheets

You have dog in your list twice! I already had the fix for the code. After
your first posting I found a similar posting and modified the code I sent
you. Here is the fx to test if the sheet already exists.

Look at his posting:
http://www.microsoft.com/office/comm...&lang=en&cr=US

Sub addsheets()

Set sheetnames = Range("B7:B25")
For Each cell In sheetnames
If cell < "" Then

Found = False
For Each sht In ThisWorkbook.Sheets
If sht.Name = cell Then
Found = True
Exit For
End If
Next sht
If Found = False Then
Worksheets.Add after:=Sheets(Sheets.Count)
ActiveSheet.Name = cell
End If
End If
Next cell

End Sub

"jlclyde" wrote:

On Nov 20, 1:39 pm, Joel wrote:
Does the sheet name already exist? Do we ned to test if the namealready
exists?

If you highlight "sht" and right click you can add it to the watch window
and see the value of sht.



"jlclyde" wrote:
On Nov 20, 1:20 pm, jlclyde wrote:
On Nov 20, 12:57 pm, Joel wrote:


The code doesn't run an extra loop. It only runs through the range of cells
specified. There is some data in the last cell that it ran that cannot be
used in a sheet name. Sheet names cannot contain the following six
characters / \ ? * [ ]. The sheet name cannot be larger than 31 characters.


I can add some additional tests for bad sheetname but can you tell me which
names it doesn't like and how you want the problem fixed.


"jlclyde" wrote:
On Nov 20, 12:16 pm, Joel wrote:
Sub addsheets()


Set sheetnames = Range("B7:B25")
For Each sht In sheetnames
if sht < "" then
Worksheets.Add after:=Sheets(Sheets.Count)
ActiveSheet.Name = sht
end
Next sht


End Sub


"jlclyde" wrote:
On Nov 20, 11:01 am, Joel wrote:
Sub addsheets()


Set sheetnames = Range("B7:B25")
For Each sht In sheetnames
Worksheets.Add after:=Sheets(Sheets.Count)
ActiveSheet.Name = sht
Next sht


End Sub


"jlclyde" wrote:
I am having trouble naming sheets based on a range of cells. I want a
new worksheet to be added and be named after new data in range
B7:B25. I will insert a button or somethign to run the macro, I just
need some help with the code to do it. The range is a list of names.
After I have entered names, I want to push a button and have the new
names be their own tabs.


Please help,
Jay- Hide quoted text -


- Show quoted text -


How do you get it to stop after the last entry and not add another
blank sheet?
Jay- Hide quoted text -


- Show quoted text -


Even when you add the if after End it still is not working properly.
It adds one extra sheet and then throws an error.
Jay- Hide quoted text -


- Show quoted text -


Joel
ActiveSheet.Name = sht (this is highlighted after I try to debug it.
It adds an extra sheet. For example if I have five names and it
currently has 2 sheets, it will add the 5 names, it will add a 6 sheet
named Sheet3 and then it will throw the error. There is nothing in
any of the other cells. I have cleared coments and deleted them
twice. Let me kow if you can think of anything to fix this.
Thanks,
Jay- Hide quoted text -


- Show quoted text -


Sub addsheets()


Set sheetnames = Range("B7", Sheet1.Range("B25").End(xlUp))
For Each sht In sheetnames
If sht < "" Then
Worksheets.Add after:=Sheets(Sheets.Count)
ActiveSheet.Name = sht
Else: Exit Sub
End If
Next sht


End Sub


This is what I changed teh code to. I thought that i would take out
any of the blank cells out of the equation.
jay- Hide quoted text -


- Show quoted text -


Here is what I have in B starting at B7
Dog
Cat
Monkey
Dog

When I run this macro

Sub addsheets()

Set sheetnames = Range("B7", Sheet1.Range("B25").End(xlUp))
For Each sht In sheetnames
If sht < "" Then
Worksheets.Add after:=Sheets(Sheets.Count)
ActiveSheet.Name = sht
Else: Exit Sub
End If
Next sht

End Sub

It adds all the right sheets and then one more. plus the other stuff
that i said. See fi maybe you can recreate my problem and tell me how
to fix it. I know that your code is close.

Thanks,
Jay

  #9   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 410
Default VBA Help naming sheets

On Nov 20, 2:02 pm, Joel wrote:
You have dog in your list twice! I already had the fix for the code. After
your first posting I found a similar posting and modified the code I sent
you. Here is the fx to test if the sheet already exists.

Look at his posting:http://www.microsoft.com/office/comm....mspx?dg=micro...

Sub addsheets()

Set sheetnames = Range("B7:B25")
For Each cell In sheetnames
If cell < "" Then

Found = False
For Each sht In ThisWorkbook.Sheets
If sht.Name = cell Then
Found = True
Exit For
End If
Next sht
If Found = False Then
Worksheets.Add after:=Sheets(Sheets.Count)
ActiveSheet.Name = cell
End If
End If
Next cell

End Sub



"jlclyde" wrote:
On Nov 20, 1:39 pm, Joel wrote:
Does the sheet name already exist? Do we ned to test if the namealready
exists?


If you highlight "sht" and right click you can add it to the watch window
and see the value of sht.


"jlclyde" wrote:
On Nov 20, 1:20 pm, jlclyde wrote:
On Nov 20, 12:57 pm, Joel wrote:


The code doesn't run an extra loop. It only runs through the range of cells
specified. There is some data in the last cell that it ran that cannot be
used in a sheet name. Sheet names cannot contain the following six
characters / \ ? * [ ]. The sheet name cannot be larger than 31 characters.


I can add some additional tests for bad sheetname but can you tell me which
names it doesn't like and how you want the problem fixed.


"jlclyde" wrote:
On Nov 20, 12:16 pm, Joel wrote:
Sub addsheets()


Set sheetnames = Range("B7:B25")
For Each sht In sheetnames
if sht < "" then
Worksheets.Add after:=Sheets(Sheets.Count)
ActiveSheet.Name = sht
end
Next sht


End Sub


"jlclyde" wrote:
On Nov 20, 11:01 am, Joel wrote:
Sub addsheets()


Set sheetnames = Range("B7:B25")
For Each sht In sheetnames
Worksheets.Add after:=Sheets(Sheets.Count)
ActiveSheet.Name = sht
Next sht


End Sub


"jlclyde" wrote:
I am having trouble naming sheets based on a range of cells. I want a
new worksheet to be added and be named after new data in range
B7:B25. I will insert a button or somethign to run the macro, I just
need some help with the code to do it. The range is a list of names.
After I have entered names, I want to push a button and have the new
names be their own tabs.


Please help,
Jay- Hide quoted text -


- Show quoted text -


How do you get it to stop after the last entry and not add another
blank sheet?
Jay- Hide quoted text -


- Show quoted text -


Even when you add the if after End it still is not working properly.
It adds one extra sheet and then throws an error.
Jay- Hide quoted text -


- Show quoted text -


Joel
ActiveSheet.Name = sht (this is highlighted after I try to debug it.
It adds an extra sheet. For example if I have five names and it
currently has 2 sheets, it will add the 5 names, it will add a 6 sheet
named Sheet3 and then it will throw the error. There is nothing in
any of the other cells. I have cleared coments and deleted them
twice. Let me kow if you can think of anything to fix this.
Thanks,
Jay- Hide quoted text -


- Show quoted text -


Sub addsheets()


Set sheetnames = Range("B7", Sheet1.Range("B25").End(xlUp))
For Each sht In sheetnames
If sht < "" Then
Worksheets.Add after:=Sheets(Sheets.Count)
ActiveSheet.Name = sht
Else: Exit Sub
End If
Next sht


End Sub


This is what I changed teh code to. I thought that i would take out
any of the blank cells out of the equation.
jay- Hide quoted text -


- Show quoted text -


Here is what I have in B starting at B7
Dog
Cat
Monkey
Dog


When I run this macro


Sub addsheets()


Set sheetnames = Range("B7", Sheet1.Range("B25").End(xlUp))
For Each sht In sheetnames
If sht < "" Then
Worksheets.Add after:=Sheets(Sheets.Count)
ActiveSheet.Name = sht
Else: Exit Sub
End If
Next sht


End Sub


It adds all the right sheets and then one more. plus the other stuff
that i said. See fi maybe you can recreate my problem and tell me how
to fix it. I know that your code is close.


Thanks,
Jay- Hide quoted text -


- Show quoted text -


Joel i am not usually that stupid..... Thank you for looking at it so
many times today. These are not the actual names that I am goign to
use and were just placeholders.

Sorry,
Jay
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 multiple sheets Amanda Excel Discussion (Misc queries) 2 April 24th 07 04:46 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


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