Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.setup
G
 
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   Report Post  
Posted to microsoft.public.excel.setup
Bob Phillips
 
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   Report Post  
Posted to microsoft.public.excel.setup
Gord Dibben
 
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   Report Post  
Posted to microsoft.public.excel.setup
Bob Phillips
 
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   Report Post  
Posted to microsoft.public.excel.setup
G
 
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   Report Post  
Posted to microsoft.public.excel.setup
G
 
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   Report Post  
Posted to microsoft.public.excel.setup
Bob Phillips
 
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   Report Post  
Posted to microsoft.public.excel.setup
Gord Dibben
 
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





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
Inserting Filtered RC cell information into other worksheets Dennis Excel Discussion (Misc queries) 10 July 30th 05 01:54 AM
Cannat paste that macro formula onto a worksheet Stephen White Excel Discussion (Misc queries) 2 May 27th 05 11:58 AM
Search/Match between 2 x separate Worksheets and populate result in third worksheet Alan Bartley Excel Discussion (Misc queries) 1 April 11th 05 05:21 AM
How do I convert numbers into words in excell worksheet? Surendra Excel Worksheet Functions 1 December 31st 04 12:17 PM
Executing macro for all worksheet from a different worksheet Biti New Users to Excel 3 December 8th 04 10:05 AM


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