Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default shorten sheet name

Hi,
I have the following code that is working well to duplicate several
time a "Template" worksheet based on a specific list on a "Config"
worksheet. The code is also changing the name of the worksheet to be
the same as the list. However, the name is sometimes too long to fit
the excel worksheet name. Is there any way to have the name to take
only the first 30 characters?
Thanks in advance for your help.

With ActiveSheet
.Name = myCell.Value
-------------------------------------------------------

Sub CreateNameSheets()
Dim TemplateWks As Worksheet
Dim ListWks As Worksheet
Dim ListRng As Range
Dim myCell As Range
Set TemplateWks = Worksheets("Template")
Set ListWks = Worksheets("Config")
With ListWks
Set ListRng = .Range("B6", .Cells(.Rows.Count,
"B").End(xlUp))
End With
For Each myCell In ListRng.Cells
TemplateWks.Copy after:=Worksheets(Worksheets.Count)
On Error Resume Next
With ActiveSheet
.Name = myCell.Value
.Range("B4").Value = myCell.Value
End With
If Err.Number < 0 Then
MsgBox "Please fix: " & ActiveSheet.Name
Err.Clear
End If
On Error GoTo 0
Next myCell
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,522
Default shorten sheet name

Pls, do NOT post in more than one group

On Sep 21, 10:15*am, Norvascom wrote:
Hi,
I have the following code that is working well to duplicate several
time a "Template" worksheet based on a specific list on a "Config"
worksheet. The code is also changing the name of the worksheet to be
the same as the list. However, the name is sometimes too long to fit
the excel worksheet name. Is there any way to have the name to take
only the first 30 characters?
Thanks in advance for your help.

* * * * With ActiveSheet
* * * * * * .Name = myCell.Value
-------------------------------------------------------

Sub CreateNameSheets()
* * Dim TemplateWks As Worksheet
* * Dim ListWks As Worksheet
* * Dim ListRng As Range
* * Dim myCell As Range
* * Set TemplateWks = Worksheets("Template")
* * Set ListWks = Worksheets("Config")
* * With ListWks
* * * * Set ListRng = .Range("B6", .Cells(.Rows.Count,
"B").End(xlUp))
* * End With
* * For Each myCell In ListRng.Cells
* * * * TemplateWks.Copy after:=Worksheets(Worksheets.Count)
* * * * On Error Resume Next
* * * * With ActiveSheet
* * * * * * .Name = myCell.Value
* * * * * * .Range("B4").Value = myCell.Value
* * * * End With
* * * * If Err.Number < 0 Then
* * * * * * MsgBox "Please fix: " & ActiveSheet.Name
* * * * * * Err.Clear
* * * * End If
* * * * On Error GoTo 0
* * Next myCell
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default shorten sheet name

On Sep 21, 11:30*am, Don Guillett wrote:
Pls, do NOT post in more than one group

On Sep 21, 10:15*am, Norvascom wrote:



Hi,
I have the following code that is working well to duplicate several
time a "Template" worksheet based on a specific list on a "Config"
worksheet. The code is also changing the name of the worksheet to be
the same as the list. However, the name is sometimes too long to fit
the excel worksheet name. Is there any way to have the name to take
only the first 30 characters?
Thanks in advance for your help.


* * * * With ActiveSheet
* * * * * * .Name = myCell.Value
-------------------------------------------------------


Sub CreateNameSheets()
* * Dim TemplateWks As Worksheet
* * Dim ListWks As Worksheet
* * Dim ListRng As Range
* * Dim myCell As Range
* * Set TemplateWks = Worksheets("Template")
* * Set ListWks = Worksheets("Config")
* * With ListWks
* * * * Set ListRng = .Range("B6", .Cells(.Rows.Count,
"B").End(xlUp))
* * End With
* * For Each myCell In ListRng.Cells
* * * * TemplateWks.Copy after:=Worksheets(Worksheets.Count)
* * * * On Error Resume Next
* * * * With ActiveSheet
* * * * * * .Name = myCell.Value
* * * * * * .Range("B4").Value = myCell.Value
* * * * End With
* * * * If Err.Number < 0 Then
* * * * * * MsgBox "Please fix: " & ActiveSheet.Name
* * * * * * Err.Clear
* * * * End If
* * * * On Error GoTo 0
* * Next myCell
End Sub- Hide quoted text -


- Show quoted text -


Sorry I intended to post in this group. My mistake.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default shorten sheet name

It's easy to truncate the name at 30 characters. If the name length is less
than 31 Left returns the name unchanged so this works for all names.

.Name = Left(myCell.Value, 30)
.Range("B4").Value = .Name

"Norvascom" wrote in message
...
On Sep 21, 11:30 am, Don Guillett wrote:
Pls, do NOT post in more than one group

On Sep 21, 10:15 am, Norvascom wrote:



Hi,
I have the following code that is working well to duplicate several
time a "Template" worksheet based on a specific list on a "Config"
worksheet. The code is also changing the name of the worksheet to be
the same as the list. However, the name is sometimes too long to fit
the excel worksheet name. Is there any way to have the name to take
only the first 30 characters?
Thanks in advance for your help.


With ActiveSheet
.Name = myCell.Value
-------------------------------------------------------


Sub CreateNameSheets()
Dim TemplateWks As Worksheet
Dim ListWks As Worksheet
Dim ListRng As Range
Dim myCell As Range
Set TemplateWks = Worksheets("Template")
Set ListWks = Worksheets("Config")
With ListWks
Set ListRng = .Range("B6", .Cells(.Rows.Count,
"B").End(xlUp))
End With
For Each myCell In ListRng.Cells
TemplateWks.Copy after:=Worksheets(Worksheets.Count)
On Error Resume Next
With ActiveSheet
.Name = myCell.Value
.Range("B4").Value = myCell.Value
End With
If Err.Number < 0 Then
MsgBox "Please fix: " & ActiveSheet.Name
Err.Clear
End If
On Error GoTo 0
Next myCell
End Sub- Hide quoted text -


- Show quoted text -


Sorry I intended to post in this group. My mistake.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default shorten sheet name

It's easy to truncate the name at 30 characters. If the name length
is less than 31 Left returns the name unchanged so this works for
all names.

.Name = Left(myCell.Value, 30)
.Range("B4").Value = .Name


It might be a good idea to Trim that first assignment just in case the
truncated text ends with a space character... no sense leaving the blank on
the end to trip up future references to the sheet name.

..Name = Trim(Left(myCell.Value, 30))

Rick Rothstein (MVP - Excel)

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
Can I shorten this any? Gregory Day Excel Worksheet Functions 1 April 10th 08 06:29 PM
Shorten the Excel Sheet nabanco Excel Worksheet Functions 7 July 19th 07 07:12 PM
Any way to shorten this up? Kevin M Excel Worksheet Functions 2 November 6th 06 07:50 PM
Shorten A Name rocket0612 Excel Discussion (Misc queries) 3 June 14th 05 11:37 AM
Is there a way to shorten this? TyeJae[_7_] Excel Programming 4 June 15th 04 01:51 AM


All times are GMT +1. The time now is 09:50 AM.

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"