Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11
Default Naming sheets after a range

I have a list of dates in A1:A15 I would automatically like to name sheets
3-18 after the values in that range.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Naming sheets after a range

There's a mismatch between the range and the number of sheets.

A1:A15 is 14 cells.
3-18 is 15 sheets.

You may have to adjust the "for irow = 3 to 18" line.


Option Explicit
Sub testme()

Dim wks As Worksheet
Dim iRow As Long

Set wks = ActiveSheet

If Sheets.Count < 18 Then
MsgBox "not enough sheets"
Exit Sub
End If

For iRow = 3 To 18
On Error Resume Next
Sheets(iRow).Name = wks.Cells(iRow - 2, "A").Value
If Err.Number < 0 Then
Err.Clear
MsgBox "Rename " & Sheets(iRow - 2).Name & " manually"
End If
On Error GoTo 0
Next iRow

End Sub




kefee85 wrote:

I have a list of dates in A1:A15 I would automatically like to name sheets
3-18 after the values in that range.


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default Naming sheets after a range

Hi,

Alt + f11 to open VB editor, right click 'This Wirkbook' and insert module.
Paste the code below in and run it.

Sub rename()
x = 3
Set MyRange = Sheets("Sheet1").Range("A1:A15")
For Each c In MyRange
Sheets(x).Name = Format(c.Value, "dd-mm-yyyy")
x = x + 1
Next
End Sub

Mike

"kefee85" wrote:

I have a list of dates in A1:A15 I would automatically like to name sheets
3-18 after the values in that range.

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Naming sheets after a range

Er,

a1:a15 is 15 cells
3-18 is 16 sheets

Doh!

And you may have to change the sheets.count line, too.

Dave Peterson wrote:

There's a mismatch between the range and the number of sheets.

A1:A15 is 14 cells.
3-18 is 15 sheets.

You may have to adjust the "for irow = 3 to 18" line.

Option Explicit
Sub testme()

Dim wks As Worksheet
Dim iRow As Long

Set wks = ActiveSheet

If Sheets.Count < 18 Then
MsgBox "not enough sheets"
Exit Sub
End If

For iRow = 3 To 18
On Error Resume Next
Sheets(iRow).Name = wks.Cells(iRow - 2, "A").Value
If Err.Number < 0 Then
Err.Clear
MsgBox "Rename " & Sheets(iRow - 2).Name & " manually"
End If
On Error GoTo 0
Next iRow

End Sub

kefee85 wrote:

I have a list of dates in A1:A15 I would automatically like to name sheets
3-18 after the values in that range.


--

Dave Peterson


--

Dave Peterson
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
Naming sheets from a cell value Tony4X4 Excel Discussion (Misc queries) 12 September 7th 09 01:55 PM
VBA Help naming sheets jlclyde Excel Discussion (Misc queries) 8 November 20th 07 09:59 PM
Naming Sheets for day of the month Socks322 Excel Discussion (Misc queries) 0 November 7th 06 03:08 PM
Naming Sheets using a range in another worksheet gazza Excel Worksheet Functions 3 September 19th 06 01:02 PM
Naming Sheets Tabs Cgbilliar Excel Worksheet Functions 2 November 5th 04 05:21 PM


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