[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.excel.programming

Re: How to create worksheet with the name "Jan. 2007".....

Don Guillett

12/12/2006 11:24:00 PM

try

Sub makeshts()
For i = 12 To 1 Step -1
myname = Format(DateSerial(2006, i, 1), "mmm yyyy")
Sheets.Add
ActiveSheet.Name = myname
Next i
End Sub
--
Don Guillett
SalesAid Software
dguillett1@austin.rr.com
"Jeffery B Paarsa" <JeffBPaarsa@Yahoo.com> wrote in message
news:746D9C4A-24E3-4336-81BC-55976DA4E02B@microsoft.com...
> Hello all,
>
> In a VBA macro I running the following code hoping to create a maximum
> number of 12 worksheets after worksheet number 3 with the worksheet name
> of
> "Jan. 2007", "Feb. 2007"....etc... What am I doing wrong... Beleive me I
> spent at least 2 hours in search to find an example code with no
> success....
>
> Private Sub SchedSheets()
> Dim mon As String
> Dim monArr() As String
> mon = "Jan.Feb.Mar.Apr.May.Jun.Jul.Aug.Sep.Oct.Nov.Dec."
> monArr = Split(mon, ".")
> Dim ws As Worksheet
> Dim mm As Integer
> Dim i As Integer
> i = 3
> m = Month(Date)
> Dim sheetName As String
> While mm < 13
> sheetName = monArr(m) & " " & Year(Date)
> Worksheets.Add after:=Sheets(i)
> ActiveWorksheet.Name = sheetName
> i = i + 1
> m = m + 1
> Wend
> End Sub
> --
> Jeff B Paarsa


2 Answers

Don Guillett

12/12/2006 11:35:00 PM

0

for after sheet3 try
Sheets.Add after:=Sheet3

--
Don Guillett
SalesAid Software
dguillett1@austin.rr.com
"Don Guillett" <dguillett1@austin.rr.com> wrote in message
news:uhsxPSkHHHA.1252@TK2MSFTNGP02.phx.gbl...
> try
>
> Sub makeshts()
> For i = 12 To 1 Step -1
> myname = Format(DateSerial(2006, i, 1), "mmm yyyy")
> Sheets.Add
> ActiveSheet.Name = myname
> Next i
> End Sub
> --
> Don Guillett
> SalesAid Software
> dguillett1@austin.rr.com
> "Jeffery B Paarsa" <JeffBPaarsa@Yahoo.com> wrote in message
> news:746D9C4A-24E3-4336-81BC-55976DA4E02B@microsoft.com...
>> Hello all,
>>
>> In a VBA macro I running the following code hoping to create a maximum
>> number of 12 worksheets after worksheet number 3 with the worksheet name
>> of
>> "Jan. 2007", "Feb. 2007"....etc... What am I doing wrong... Beleive me I
>> spent at least 2 hours in search to find an example code with no
>> success....
>>
>> Private Sub SchedSheets()
>> Dim mon As String
>> Dim monArr() As String
>> mon = "Jan.Feb.Mar.Apr.May.Jun.Jul.Aug.Sep.Oct.Nov.Dec."
>> monArr = Split(mon, ".")
>> Dim ws As Worksheet
>> Dim mm As Integer
>> Dim i As Integer
>> i = 3
>> m = Month(Date)
>> Dim sheetName As String
>> While mm < 13
>> sheetName = monArr(m) & " " & Year(Date)
>> Worksheets.Add after:=Sheets(i)
>> ActiveWorksheet.Name = sheetName
>> i = i + 1
>> m = m + 1
>> Wend
>> End Sub
>> --
>> Jeff B Paarsa
>
>


Peter T

12/12/2006 11:37:00 PM

0

You beat me to it! here's mine anyway

Sub test()
Dim i As Long, d As Long

d = -15
For i = 0 To 11
d = d + 30
Worksheets.Add(after:=Worksheets(3 + i)).Name = Format(d, "mmm 2007")
Next

End Sub

Assumes dealing with the activeworkbook, at least 3 sheets exist per your
requirement, no same name sheets exist.

Regards,
Peter T

"Don Guillett" <dguillett1@austin.rr.com> wrote in message
news:uhsxPSkHHHA.1252@TK2MSFTNGP02.phx.gbl...
> try
>
> Sub makeshts()
> For i = 12 To 1 Step -1
> myname = Format(DateSerial(2006, i, 1), "mmm yyyy")
> Sheets.Add
> ActiveSheet.Name = myname
> Next i
> End Sub
> --
> Don Guillett
> SalesAid Software
> dguillett1@austin.rr.com
> "Jeffery B Paarsa" <JeffBPaarsa@Yahoo.com> wrote in message
> news:746D9C4A-24E3-4336-81BC-55976DA4E02B@microsoft.com...
> > Hello all,
> >
> > In a VBA macro I running the following code hoping to create a maximum
> > number of 12 worksheets after worksheet number 3 with the worksheet name
> > of
> > "Jan. 2007", "Feb. 2007"....etc... What am I doing wrong... Beleive me I
> > spent at least 2 hours in search to find an example code with no
> > success....
> >
> > Private Sub SchedSheets()
> > Dim mon As String
> > Dim monArr() As String
> > mon = "Jan.Feb.Mar.Apr.May.Jun.Jul.Aug.Sep.Oct.Nov.Dec."
> > monArr = Split(mon, ".")
> > Dim ws As Worksheet
> > Dim mm As Integer
> > Dim i As Integer
> > i = 3
> > m = Month(Date)
> > Dim sheetName As String
> > While mm < 13
> > sheetName = monArr(m) & " " & Year(Date)
> > Worksheets.Add after:=Sheets(i)
> > ActiveWorksheet.Name = sheetName
> > i = i + 1
> > m = m + 1
> > Wend
> > End Sub
> > --
> > Jeff B Paarsa
>
>