Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Change default number to default text?

Having some difficulties figuring out how to change some default
text. After a few minutes, figured out that "default text" would
bring up better hits in googling this group but nothing comes up that
I can work with since I am rather limited in my vb abilities.

I have this script that was a kind gift a couple of years ago or so:
----------------------------------------
Sub NewSheet_Add()
Worksheets("TEMPLATE").Copy Befo=Worksheets(1)
Worksheets(1).Visible = xlSheetVisible
ActiveSheet.Unprotect 'place at the beginning of the code

Dim vResponse As Variant
Do
vResponse = Application.InputBox( _
Prompt:="Enter a name for the new tab.", _
Title:="Tab Name", _
Default:=Format(Day(Date), "000000"), _
Type:=2)
If vResponse = False Then Exit Sub 'User cancelled
Loop Until vResponse < 0 And vResponse < 1000000
With Range("A2")
.NumberFormat = "000000"
.Value = vResponse
End With

On Error GoTo CanNotRename
ActiveSheet.Name = Format(vResponse, "000000")
On Error GoTo 0
Exit Sub

'Error code
CanNotRename:
MsgBox "Can't rename sheet to " & Format(vResponse, "000000")
Resume Next

ActiveSheet.Protect ' place at end of code
End Sub
----------------------------------------

It allows me to "start" a new sheet and then name it right then and
there. But the naming convention was a number. I need text with the
default text being, say, "Tab ", just to give an example

How can I change the above to reflect a new format for the tab name,
pls?

Thanks! :oD
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Change default number to default text?

Hi,

Maybe something like this

Sub NewSheet_Add()
Worksheets("TEMPLATE").Copy Befo=Worksheets(1)
Worksheets(1).Visible = xlSheetVisible
ActiveSheet.Unprotect 'place at the beginning of the code

Dim vResponse As Variant
Do
vResponse = Application.InputBox( _
Prompt:="Enter a name for the new tab.", _
Title:="Tab Name", _
Default:="Tab", _
Type:=2)
If vResponse = False Then Exit Sub 'User cancelled
Loop Until vResponse < ""
With Range("A2")
.Value = vResponse
End With

On Error GoTo CanNotRename
ActiveSheet.Name = Format(vResponse, "000000")
On Error GoTo 0
Exit Sub

'Error code
CanNotRename:
MsgBox "Can't rename sheet to " & vResponse
Resume Next

ActiveSheet.Protect ' place at end of code
End Sub


Mike

" wrote:

Having some difficulties figuring out how to change some default
text. After a few minutes, figured out that "default text" would
bring up better hits in googling this group but nothing comes up that
I can work with since I am rather limited in my vb abilities.

I have this script that was a kind gift a couple of years ago or so:
----------------------------------------
Sub NewSheet_Add()
Worksheets("TEMPLATE").Copy Befo=Worksheets(1)
Worksheets(1).Visible = xlSheetVisible
ActiveSheet.Unprotect 'place at the beginning of the code

Dim vResponse As Variant
Do
vResponse = Application.InputBox( _
Prompt:="Enter a name for the new tab.", _
Title:="Tab Name", _
Default:=Format(Day(Date), "000000"), _
Type:=2)
If vResponse = False Then Exit Sub 'User cancelled
Loop Until vResponse < 0 And vResponse < 1000000
With Range("A2")
.NumberFormat = "000000"
.Value = vResponse
End With

On Error GoTo CanNotRename
ActiveSheet.Name = Format(vResponse, "000000")
On Error GoTo 0
Exit Sub

'Error code
CanNotRename:
MsgBox "Can't rename sheet to " & Format(vResponse, "000000")
Resume Next

ActiveSheet.Protect ' place at end of code
End Sub
----------------------------------------

It allows me to "start" a new sheet and then name it right then and
there. But the naming convention was a number. I need text with the
default text being, say, "Tab ", just to give an example

How can I change the above to reflect a new format for the tab name,
pls?

Thanks! :oD

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
How do I change Excel default number? PatrickR Excel Discussion (Misc queries) 3 January 28th 10 05:09 PM
how do i change the default from a date to a number? Habbakuk Excel Discussion (Misc queries) 1 April 21st 07 01:42 PM
Change Default Number Format krademac Excel Discussion (Misc queries) 1 October 19th 06 11:36 PM
How do I change default number settings? Siberian Excel Worksheet Functions 1 November 27th 05 02:31 AM
How do I change the default number format? Zither Excel Discussion (Misc queries) 4 March 13th 05 06:04 AM


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