Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Help needed with Macro


I have a Workbook with 13 sheets, the first is a Control sheet. On the
control sheet I have a button (Macro details below) which when clicked
should rename the other 12 sheets according to data in cells A4:A15

Sub namesheets_as_per_list_on_worksheet()
Dim arr As Variant
arr = Range("a4:a15").Value
For i = LBound(arr) To UBound(arr)
Sheets(i + 1).Activate
Sheets(i).Name = arr(i, 1)
Next i
End Sub

The conrtrol sheet is the first sheet in the workbook, and gets renamed
when I run the macro, whilst sheet 13 does not change. What changes does
the Macro require so that it renames sheets 2-13, ignoring sheet 1 the
control sheet


--
Paul Sheppard


------------------------------------------------------------------------
Paul Sheppard's Profile: http://www.excelforum.com/member.php...o&userid=24783
View this thread: http://www.excelforum.com/showthread...hreadid=398905

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default Help needed with Macro

Hi Paul

This is happening because by default array indexes start at 0. You can
change this to 1 by adding the statement "Option Base 1" to your module but
you may be better off trying it like this:

Sub namesheets_as_per_list_on_worksheet()
Dim i As Integer
For i = 2 To 13
Sheets(i).Name = Cells(i + 2, 1).Value
Next i
End Sub

Hope this helps
Rowan
"Paul Sheppard" wrote:


I have a Workbook with 13 sheets, the first is a Control sheet. On the
control sheet I have a button (Macro details below) which when clicked
should rename the other 12 sheets according to data in cells A4:A15

Sub namesheets_as_per_list_on_worksheet()
Dim arr As Variant
arr = Range("a4:a15").Value
For i = LBound(arr) To UBound(arr)
Sheets(i + 1).Activate
Sheets(i).Name = arr(i, 1)
Next i
End Sub

The conrtrol sheet is the first sheet in the workbook, and gets renamed
when I run the macro, whilst sheet 13 does not change. What changes does
the Macro require so that it renames sheets 2-13, ignoring sheet 1 the
control sheet


--
Paul Sheppard


------------------------------------------------------------------------
Paul Sheppard's Profile: http://www.excelforum.com/member.php...o&userid=24783
View this thread: http://www.excelforum.com/showthread...hreadid=398905


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Help needed with Macro


you almost had it!!!
you only have to change:

Sheets(i).Name = arr(i, 1)

to

Sheets(*i + 1*).Name = arr(i, 1)

as you did with the previous line...

just a note... you don't have to activate the sheet to change its
name...
at least, that is what happens with my office (2003)....

:)

Paul Sheppard Wrote:
I have a Workbook with 13 sheets, the first is a Control sheet. On the
control sheet I have a button (Macro details below) which when clicked
should rename the other 12 sheets according to data in cells A4:A15

Sub namesheets_as_per_list_on_worksheet()
Dim arr As Variant
arr = Range("a4:a15").Value
For i = LBound(arr) To UBound(arr)
Sheets(i + 1).Activate
Sheets(i).Name = arr(i, 1)
Next i
End Sub

The conrtrol sheet is the first sheet in the workbook, and gets renamed
when I run the macro, whilst sheet 13 does not change. What changes does
the Macro require so that it renames sheets 2-13, ignoring sheet 1 the
control sheet



--
T-®ex
------------------------------------------------------------------------
T-®ex's Profile: http://www.excelforum.com/member.php...o&userid=26572
View this thread: http://www.excelforum.com/showthread...hreadid=398905

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Help needed with Macro


T-®ex Wrote:
you almost had it!!!
you only have to change:

Sheets(i).Name = arr(i, 1)

to

Sheets(*i + 1*).Name = arr(i, 1)

as you did with the previous line...

just a note... you don't have to activate the sheet to change its
name...
at least, that is what happens with my office (2003)....

:)


Thanks T-®ex, much appreciated


--
Paul Sheppard


------------------------------------------------------------------------
Paul Sheppard's Profile: http://www.excelforum.com/member.php...o&userid=24783
View this thread: http://www.excelforum.com/showthread...hreadid=398905

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
Macro needed Bryan[_4_] New Users to Excel 3 February 16th 08 07:39 PM
Macro Help Needed - Excel 2007 - Print Macro with Auto Sort Gavin Excel Worksheet Functions 0 May 17th 07 01:20 PM
Macro needed to Paste Values and prevent Macro operation thunderfoot Excel Discussion (Misc queries) 1 June 11th 05 12:44 AM
Macro needed to Paste Values and prevent Macro operation thunderfoot Excel Discussion (Misc queries) 0 June 10th 05 03:38 PM
Macro Needed Please Ant Nutting Excel Programming 2 May 11th 04 03:35 PM


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