LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default naming a sheet automatically

There was a typo
Sheets(1).Name = strName

When I changed that to Sheets(i).Name = strName it worked. There must
be at least 12 sheets in the workbook and the sheet with the date in L7 must
be the activesheet when you run it.

Sub AABBCC()
If Range("t7").Value < "" Then
If IsDate(Range("L7")) Then
Set dt = Range("L7")
For i = 1 To 12
strName = Format(DateSerial(Year(dt), Month(dt) + i - 1, 1), "mmmm")
Sheets(i).Name = strName
Next
ThisWorkbook.Save
Else
MsgBox " Invalid date in L7"
End If
Else
If MsgBox("You omitted your name. Do " _
& "you still want to exit?", vbYesNo) = vbNo _
Then
Sheets(1).Name = "Est 1"
Cancel = True
End If
End If
End Sub

The above worked as I expected. (In only tested the condition where there
is a date in L7 and T7 has the formula you talked about.

--
Regards,
Tom Ogilvy


"NWilcox" wrote in message
...
I put it in just as it was starting with the same statement. I saved it

and
closed it. I closed the workbook and reopened it. The page was named the
month prior, and still only the first sheet. I then tried to put it each
sheet 1 and sheet 2. I had the same results. What am I doing wrong? I
appreciate your help.



"Tom Ogilvy" wrote:

If Range("t7").Value < "" Then
if isdate(Range("L7")) then
set dt = Range("L7")
for i = 1 to 12
strName = format(DateSerial(year(dt),Month(dt)+i-1,1),"mmmm")
Sheets(1).Name = strName
Next
ThisWorkbook.Save
else
msgbox " Invalid date in L7"
end if
Else
If MsgBox("You omitted your name. Do " _
& "you still want to exit?", vbYesNo) = vbNo _
Then
Sheets(1).Name = "Est 1"
Cancel = True
End If
End If
End Sub

--
regards,
Tom Ogilvy


"NWilcox" wrote in message
...
Hi, I'm new to Excel VBA. I'm working on a workbook with 12 sheets.

On
Sheet 1 the user inputs the date which they are beginning on. It then

puts
the end of the month in the next cell. On Sheet 2 - 12, the first

date is
automatically changed to the next month and the end of the month is

added.
The user wants me to automatically name each sheet for the month is
represents. I've tried to use all the steps in this discussion and

can't
seem to get them to change automatically. I managed to get Sheet 1 to

change
to the proper month by making a cell T7 name the month using

=text(L7,"mmmm")
where L7 is the date input cell. I used the following code in the
ThisWorkbook section:

Option Explicit

Private Sub Workbook_BeforeClose(Cancel As Boolean)
' This procedure changes the worksheet name to month name

Dim strName As String

If Range("t7").Value < "" Then
strName = Range("t7").Value
Sheets(1).Name = strName
Else
If MsgBox("You omitted your name. Do " _
& "you still want to exit?", vbYesNo) = vbNo _
Then
Sheets(1).Name = "Est 1"
Cancel = True
End If
End If
End Sub

Can anyone help me get this to name each sheet according to the proper

month?

TIA



"terry freedman" wrote:

Hi

is it possible to automatically name a sheet as the value in one of
the cels? I tried doing this in the View code section of a sheet,

but
nothing works. Also, it falls down if the value in the cell has a
space in it.

TIA

Terry
==
Terry Freedman
For articles on e-learning and ICT, and to subscribe to Computers in

Classrooms, visit http://www.ictineducation.org






 
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
Automatically naming and linking controls Blue Max Excel Worksheet Functions 6 December 16th 08 06:04 AM
Stop 2007 automatically naming ranges Bromers Excel Discussion (Misc queries) 0 May 29th 07 11:16 AM
Automatically naming a tab jga Excel Discussion (Misc queries) 1 December 21st 04 03:30 PM
Naming a new sheet. Rich Cooper Excel Programming 1 May 25th 04 09:56 PM
Automatically naming a worksheet tab with dates? Dick Kusleika[_2_] Excel Programming 1 September 6th 03 02:57 AM


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