Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Max Max is offline
external usenet poster
 
Posts: 9,221
Default Renaming sheets from a list

Hi guys,

In Sheet1, A1:B3, I have listed:

DistA Dist1
DistB Dist2
DistC Dist3

where in A1:A3 are 3 existing sheetnames
that I want to rename as in B1:B3, via a sub

Thanks
--
Rgds
Max
xl 97
---
GMT+8, 1° 22' N 103° 45' E
xdemechanik <atyahoo<dotcom
----


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Renaming sheets from a list

Sub ReplaceSheetNames()

Dim sht As Worksheet
Dim shtChange As String
Dim i As Integer

Set sht = Sheets("Sheet1")

'allow room to grow
For i = 1 To sht.Cells(1).CurrentRegion.Rows.Count
shtChange = sht.Cells(i, 1).Value 'get sheet name
Sheets(shtChange).Name = sht.Cells(i, 2).Value 'change sheetname

Next i

End Sub

Regards
Andrew
excelthoughts.com

  #3   Report Post  
Posted to microsoft.public.excel.programming
Max Max is offline
external usenet poster
 
Posts: 9,221
Default Renaming sheets from a list

Thanks, Andrew !
Runs smooth.

Could I trouble you for a desired flexibility ?

I'll like to be able to select the source range for the sub to execute,
e.g.: A1:B3 in Sheet1 in the OP. This source range could be of any size in
any sheet, but it will be a 2 column range. Thanks
--
Rgds
Max
xl 97
---
GMT+8, 1° 22' N 103° 45' E
xdemechanik <atyahoo<dotcom
----
"excelthoughts" wrote in message
oups.com...
Sub ReplaceSheetNames()

Dim sht As Worksheet
Dim shtChange As String
Dim i As Integer

Set sht = Sheets("Sheet1")

'allow room to grow
For i = 1 To sht.Cells(1).CurrentRegion.Rows.Count
shtChange = sht.Cells(i, 1).Value 'get sheet name
Sheets(shtChange).Name = sht.Cells(i, 2).Value 'change sheetname

Next i

End Sub

Regards
Andrew
excelthoughts.com



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Renaming sheets from a list

Hi Max,

Could I trouble you for a desired flexibility ?

I'll like to be able to select the source range for the sub to execute,
e.g.: A1:B3 in Sheet1 in the OP. This source range could be of any size
in
any sheet, but it will be a 2 column range. Thanks



Try:

'-------------------------------------------
Sub Tester1()
Dim rCell As Range

For Each rCell In Selection.Columns(1).Cells
On Error GoTo ErrHandler
If SheetExists(rCell.Value) Then
Sheets(rCell.Value).Name = _
rCell(1, 2).Value
Else
MsgBox "Cell " & rCell.Address(0, 0, , 1) & _
" does not contain an existing sheet name"
End If
Continue:
Next

Exit Sub

ErrHandler:
MsgBox rCell(1, 2).Address(0, 0, , 1) & _
" Contains a duplicated or invalid sheet name"

Resume Continue

End Sub

'-------------------------------------------
Function SheetExists(sName As String, _
Optional ByVal wb As Workbook) As Boolean

On Error Resume Next
If wb Is Nothing Then Set wb = ActiveWorkbook
SheetExists = CBool(Len(Sheets(sName).Name))
End Function
'-------------------------------------------


---
Regards,
Norman



"Max" wrote in message
...
Thanks, Andrew !
Runs smooth.

Could I trouble you for a desired flexibility ?

I'll like to be able to select the source range for the sub to execute,
e.g.: A1:B3 in Sheet1 in the OP. This source range could be of any size
in
any sheet, but it will be a 2 column range. Thanks
--
Rgds
Max
xl 97
---
GMT+8, 1° 22' N 103° 45' E
xdemechanik <atyahoo<dotcom
----
"excelthoughts" wrote in message
oups.com...
Sub ReplaceSheetNames()

Dim sht As Worksheet
Dim shtChange As String
Dim i As Integer

Set sht = Sheets("Sheet1")

'allow room to grow
For i = 1 To sht.Cells(1).CurrentRegion.Rows.Count
shtChange = sht.Cells(i, 1).Value 'get sheet name
Sheets(shtChange).Name = sht.Cells(i, 2).Value 'change sheetname

Next i

End Sub

Regards
Andrew
excelthoughts.com





  #5   Report Post  
Posted to microsoft.public.excel.programming
Max Max is offline
external usenet poster
 
Posts: 9,221
Default Renaming sheets from a list

Marvellous, Norman !
Runs great ! Thanks.
--
Rgds
Max
xl 97
---
GMT+8, 1° 22' N 103° 45' E
xdemechanik <atyahoo<dotcom
----


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
Renaming Sheets Accor Excel Discussion (Misc queries) 6 August 15th 08 04:43 PM
renaming all work-sheets at once Narendra Boga[_2_] Excel Discussion (Misc queries) 4 June 6th 07 03:24 AM
Renaming sheets from a list in a column Max Excel Programming 6 May 18th 05 04:03 AM
Renaming sheets Adri[_2_] Excel Programming 5 April 5th 04 10:09 PM
renaming sheets Jeremy Excel Programming 2 November 28th 03 04:46 PM


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