Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default rename the new worksheet

i kindly ask for help.
in sheet1 i have a list, i need to create a new worksheet and name it with
the value of cell which i selected in this list. i tried something like this,
but itĀ“s surely very simple

Sub Create()
Dim ws As Worksheet
Dim wsName As String
If Not IsEmpty(ActiveSheet.ActiveCell.Value) Then
Set ws = Worksheets.Add
ws.Move After:=Sheets(Sheets.Count)
ws.Name = ActiveSheet.ActiveCell.Text
End If
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default rename the new worksheet

Sub Create()
Dim ws As Worksheet
Dim wsName As String
If Not IsEmpty(ActiveCell) Then
newname = ActiveCell.Value
Set ws = Worksheets.Add
ws.Move After:=Sheets(Sheets.Count)
ws.Name = newname
End If
End Sub

you needed a little fix to the IsEmpty. You also need to capture the tab
name before the .Add

After the .Add the ActiveSheet becomes the new sheet!! Which is, of course,
totally empty.

--
Gary''s Student - gsnu200713
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default rename the new worksheet

Sub Create()
Dim cell As Range

For Each cell In Selection
If Not IsEmpty(cell) Then
Worksheets.Add(After:=Worksheets(Worksheets.Count) ).Name =
cell.Value
End If
Next cell

End Sub


--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"raraschek" wrote in message
...
i kindly ask for help.
in sheet1 i have a list, i need to create a new worksheet and name it with
the value of cell which i selected in this list. i tried something like
this,
but it“s surely very simple

Sub Create()
Dim ws As Worksheet
Dim wsName As String
If Not IsEmpty(ActiveSheet.ActiveCell.Value) Then
Set ws = Worksheets.Add
ws.Move After:=Sheets(Sheets.Count)
ws.Name = ActiveSheet.ActiveCell.Text
End If
End Sub



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default rename the new worksheet

Sub Create()
Dim ws As Worksheet
Dim wsName As String
If Not IsEmpty(ActiveCell) Then
newname = ActiveCell.Value
Set ws = Worksheets.Add
ws.Move After:=Sheets(Sheets.Count)
ws.Name = newname
End If
End Sub

you needed a little fix to the IsEmpty. You also need to capture the
tab name before the .Add

After the .Add the ActiveSheet becomes the new sheet!! Which is, of
course, totally empty.


Is it not also a good idea to test that there isn't already a worksheet of
the intended name before you name the new one?

Before ws.Name = newname

put:

Dim wks As Worksheet
For Each wks In ActiveWorkbook.Worksheets
If wks.Name = newname Then
<ask user how to proceed via msgbox - e.g. delete the exitsting one,
etc
End If
Next wks


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default rename the new worksheet

Yes it is a good idea. If the name already exists, an error will be thrown
and the new sheet will be left with its birthname - like Sheet8
--
Gary''s Student - gsnu200713


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default rename the new worksheet

Thanks a lot. I tried to implement also the test of existing ws, but it
didnĀ“t work well.

"Gary''s Student" wrote:

Yes it is a good idea. If the name already exists, an error will be thrown
and the new sheet will be left with its birthname - like Sheet8
--
Gary''s Student - gsnu200713

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 information from one worksheet, to rename inserted worksheet Lyn Excel Worksheet Functions 0 March 24th 06 12:54 AM
why can't I rename my worksheet? cfc1905 Excel Discussion (Misc queries) 2 February 13th 06 03:19 PM
rename worksheet Anthony Excel Discussion (Misc queries) 4 July 13th 05 01:16 AM
rename worksheet Ciara[_2_] Excel Programming 2 June 14th 05 09:41 AM
Rename worksheet Donald Duck Excel Programming 3 August 17th 04 10:15 AM


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