A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » Setting up and Configuration
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Macro to convert Name of worksheet



 
 
Thread Tools Display Modes
  #1  
Old November 21st, 2005, 04:31 PM posted to microsoft.public.excel.setup
external usenet poster
 
Posts: n/a
Default Macro to convert Name of worksheet

I want to change the name of all the worksheets by using a table in another
worksheet. The table contains one column for long names and another column
for short names. When the current worksheet name matches the long name
column, the name is change to the short name.

Thanks,
G
  #2  
Old November 21st, 2005, 06:56 PM posted to microsoft.public.excel.setup
external usenet poster
 
Posts: n/a
Default Macro to convert Name of worksheet


Dim iPos As Long
Dim wks As Worksheet

For Each wks In ActiveWorkbook.Worksheets
On Error Resume Next
iPos = Application.Match(wks.Name, Range("LongNames"), 0)
On Error GoTo 0
If iPos 0 Then
wks.Name = Range("ShortNames").Cells(iPos, 1)
End If
Next wks


--

HTH

RP
(remove nothere from the email address if mailing direct)


"G" wrote in message
...
I want to change the name of all the worksheets by using a table in

another
worksheet. The table contains one column for long names and another

column
for short names. When the current worksheet name matches the long name
column, the name is change to the short name.

Thanks,
G



  #3  
Old November 21st, 2005, 10:39 PM posted to microsoft.public.excel.setup
external usenet poster
 
Posts: n/a
Default Macro to convert Name of worksheet

Cool Bob

And I even understand it!!g


Gord

On Mon, 21 Nov 2005 18:56:56 -0000, "Bob Phillips"
wrote:


Dim iPos As Long
Dim wks As Worksheet

For Each wks In ActiveWorkbook.Worksheets
On Error Resume Next
iPos = Application.Match(wks.Name, Range("LongNames"), 0)
On Error GoTo 0
If iPos 0 Then
wks.Name = Range("ShortNames").Cells(iPos, 1)
End If
Next wks


  #4  
Old November 21st, 2005, 10:54 PM posted to microsoft.public.excel.setup
external usenet poster
 
Posts: n/a
Default Macro to convert Name of worksheet

Thanks Gord.

Bob


"Gord Dibben" gorddibbATshawDOTca wrote in message
...
Cool Bob

And I even understand it!!g


Gord

On Mon, 21 Nov 2005 18:56:56 -0000, "Bob Phillips"
wrote:


Dim iPos As Long
Dim wks As Worksheet

For Each wks In ActiveWorkbook.Worksheets
On Error Resume Next
iPos = Application.Match(wks.Name, Range("LongNames"), 0)
On Error GoTo 0
If iPos 0 Then
wks.Name = Range("ShortNames").Cells(iPos, 1)
End If
Next wks




  #5  
Old November 22nd, 2005, 05:40 PM posted to microsoft.public.excel.setup
external usenet poster
 
Posts: n/a
Default Macro to convert Name of worksheet

I used both your original example and the modified version below. Neither
seems to run. I get no error msg or any results. I understand what the code
is trying to do, I'm I forgetting something? Thanks again!

Sub Rename()

Dim iPos As Long
Dim wks As Worksheet

For Each wks In ActiveWorkbook.Worksheets
On Error Resume Next
iPos = Application.Match(ws.Name, Range("BrokerInfo!a2:a84"), 0)
On Error GoTo 0
If iPos 0 Then
ws.Name = Range("BrokerInfo!b2:b84").Cells(iPos, 1)
End If
Next wks
End Sub



"Bob Phillips" wrote:


Dim iPos As Long
Dim wks As Worksheet

For Each wks In ActiveWorkbook.Worksheets
On Error Resume Next
iPos = Application.Match(wks.Name, Range("LongNames"), 0)
On Error GoTo 0
If iPos 0 Then
wks.Name = Range("ShortNames").Cells(iPos, 1)
End If
Next wks


--

HTH

RP
(remove nothere from the email address if mailing direct)


"G" wrote in message
...
I want to change the name of all the worksheets by using a table in

another
worksheet. The table contains one column for long names and another

column
for short names. When the current worksheet name matches the long name
column, the name is change to the short name.

Thanks,
G




  #6  
Old November 22nd, 2005, 07:56 PM posted to microsoft.public.excel.setup
external usenet poster
 
Posts: n/a
Default Macro to convert Name of worksheet

It works (just needed to change ws.name to wks.name since it's wks after
dim). Thanks for the help!!!!

"G" wrote:

I used both your original example and the modified version below. Neither
seems to run. I get no error msg or any results. I understand what the code
is trying to do, I'm I forgetting something? Thanks again!

Sub Rename()

Dim iPos As Long
Dim wks As Worksheet

For Each wks In ActiveWorkbook.Worksheets
On Error Resume Next
iPos = Application.Match(ws.Name, Range("BrokerInfo!a2:a84"), 0)
On Error GoTo 0
If iPos 0 Then
ws.Name = Range("BrokerInfo!b2:b84").Cells(iPos, 1)
End If
Next wks
End Sub



"Bob Phillips" wrote:


Dim iPos As Long
Dim wks As Worksheet

For Each wks In ActiveWorkbook.Worksheets
On Error Resume Next
iPos = Application.Match(wks.Name, Range("LongNames"), 0)
On Error GoTo 0
If iPos 0 Then
wks.Name = Range("ShortNames").Cells(iPos, 1)
End If
Next wks


--

HTH

RP
(remove nothere from the email address if mailing direct)


"G" wrote in message
...
I want to change the name of all the worksheets by using a table in

another
worksheet. The table contains one column for long names and another

column
for short names. When the current worksheet name matches the long name
column, the name is change to the short name.

Thanks,
G




  #7  
Old November 22nd, 2005, 09:20 PM posted to microsoft.public.excel.setup
external usenet poster
 
Posts: n/a
Default Macro to convert Name of worksheet

Well spotted. And you did it yourself, which is a better all round :-))

Bob


"G" wrote in message
...
It works (just needed to change ws.name to wks.name since it's wks after
dim). Thanks for the help!!!!

"G" wrote:

I used both your original example and the modified version below.

Neither
seems to run. I get no error msg or any results. I understand what the

code
is trying to do, I'm I forgetting something? Thanks again!

Sub Rename()

Dim iPos As Long
Dim wks As Worksheet

For Each wks In ActiveWorkbook.Worksheets
On Error Resume Next
iPos = Application.Match(ws.Name, Range("BrokerInfo!a2:a84"), 0)
On Error GoTo 0
If iPos 0 Then
ws.Name = Range("BrokerInfo!b2:b84").Cells(iPos, 1)
End If
Next wks
End Sub



"Bob Phillips" wrote:


Dim iPos As Long
Dim wks As Worksheet

For Each wks In ActiveWorkbook.Worksheets
On Error Resume Next
iPos = Application.Match(wks.Name, Range("LongNames"), 0)
On Error GoTo 0
If iPos 0 Then
wks.Name = Range("ShortNames").Cells(iPos, 1)
End If
Next wks


--

HTH

RP
(remove nothere from the email address if mailing direct)


"G" wrote in message
...
I want to change the name of all the worksheets by using a table in
another
worksheet. The table contains one column for long names and another
column
for short names. When the current worksheet name matches the long

name
column, the name is change to the short name.

Thanks,
G





  #8  
Old November 22nd, 2005, 09:31 PM posted to microsoft.public.excel.setup
external usenet poster
 
Posts: n/a
Default Macro to convert Name of worksheet

It appears to me that you have not properly named the ranges as Bob's code
uses range names "Longnames" and "Shortnames"

On BrokerInfo sheet select A2:A84 and InsertNameDefine

Name this range "Longnames"(no quotes)

Select B2:B84 and do the same for "Shortnames".

Now run Bob's macro.

On your code "BrokerInfo!a2:a84" doesn't appear to be a named range.

Looks like a range address which VBA will not accept.

You also have a couple of typos.......

change both instances of ws.name to wks.name


Gord Dibben Excel MVP

On Tue, 22 Nov 2005 09:40:20 -0800, "G" wrote:

I used both your original example and the modified version below. Neither
seems to run. I get no error msg or any results. I understand what the code
is trying to do, I'm I forgetting something? Thanks again!

Sub Rename()

Dim iPos As Long
Dim wks As Worksheet

For Each wks In ActiveWorkbook.Worksheets
On Error Resume Next
iPos = Application.Match(ws.Name, Range("BrokerInfo!a2:a84"), 0)
On Error GoTo 0
If iPos 0 Then
ws.Name = Range("BrokerInfo!b2:b84").Cells(iPos, 1)
End If
Next wks
End Sub



"Bob Phillips" wrote:


Dim iPos As Long
Dim wks As Worksheet

For Each wks In ActiveWorkbook.Worksheets
On Error Resume Next
iPos = Application.Match(wks.Name, Range("LongNames"), 0)
On Error GoTo 0
If iPos 0 Then
wks.Name = Range("ShortNames").Cells(iPos, 1)
End If
Next wks


--

HTH

RP
(remove nothere from the email address if mailing direct)


"G" wrote in message
...
I want to change the name of all the worksheets by using a table in

another
worksheet. The table contains one column for long names and another

column
for short names. When the current worksheet name matches the long name
column, the name is change to the short name.

Thanks,
G





 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
convert column worksheet to database PK General Discussion 1 November 8th, 2005 02:06 PM
Convert Word Macro to Access Procedure? Tom Brown General Discussion 1 November 1st, 2005 04:36 AM
hide a worksheet so that a macro can still find it frendabrenda1 Worksheet Functions 1 June 17th, 2005 04:30 PM
formula to convert a worksheet from upper case to proper Nancy Cantave General Discussion 3 October 14th, 2004 02:21 PM
Create a macro to copy worksheet 52 times & rename Harald Staff Worksheet Functions 0 November 8th, 2003 09:38 AM


All times are GMT +1. The time now is 06:54 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.