insert sheet and naming it

  • Thread starter Thread starter hans
  • Start date Start date
H

hans

I have a workbook containing the workrosters for each week.
the sheets are named 1,2,3,4, etc (This are the week numbers)
Sheet 54 is the original sheet from witch i copy.
Other sheets have normal names like "tijden", "medewerkers", etc etc

If my last rostersheet is named 9, i would like to know how to insert a new
sheet called 10 after 9.

I would like a vba solution.
Can someone help.

Greetings Hans
 
Hi Hans,
Sheet 54 is the original sheet from witch i copy.
Other sheets have normal names

If my last rostersheet is named 9, i would like to know how to insert a new
sheet called 10 after 9.

try

Sheets("54").Select
Sheets.Add

or if you want to have a copy of sheet 54

Sheets("54").Select
Sheets("").Copy Before:=Sheets("54")


Best

Markus
 
Dim sh as Worksheet, sName as String
Dim MaxWeek as Long, MaxIndex as Long

MaxWeek = 0
MaxIndex = 0
for each sh in ActiveWorkbook.Sheets
sName = sh.name
if isnumeric(sName) then
if clng(sName) < 53 then
if clng(sName) > MaxWeek then
MaxWeek = clng(sName)
MaxIndex = sh.Index
end if
End if
end if
Next
Worksheets.Add(After:=worksheets(MaxIndex)).Name _
= cStr(MaxWeek + 1)
 
Left off the last part

Dim sh as Worksheet, sName as String
Dim MaxWeek as Long, MaxIndex as Long

MaxWeek = 0
MaxIndex = 0
for each sh in ActiveWorkbook.Sheets
sName = sh.name
if isnumeric(sName) then
if clng(sName) < 53 then
if clng(sName) > MaxWeek then
MaxWeek = clng(sName)
MaxIndex = sh.Index
end if
End if
end if
Next
Worksheets.Add(After:=worksheets(MaxIndex)).Name _
= cStr(MaxWeek + 1)
worksheets("54").Cells.copy worksheets(cStr(MaxWeek + 1))
 
Thanks, this works perfectly.

Greetings Hans


Tom Ogilvy said:
Left off the last part

Dim sh as Worksheet, sName as String
Dim MaxWeek as Long, MaxIndex as Long

MaxWeek = 0
MaxIndex = 0
for each sh in ActiveWorkbook.Sheets
sName = sh.name
if isnumeric(sName) then
if clng(sName) < 53 then
if clng(sName) > MaxWeek then
MaxWeek = clng(sName)
MaxIndex = sh.Index
end if
End if
end if
Next
Worksheets.Add(After:=worksheets(MaxIndex)).Name _
= cStr(MaxWeek + 1)
worksheets("54").Cells.copy worksheets(cStr(MaxWeek + 1))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top