ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Loop worksheets (https://www.excelbanter.com/excel-programming/283513-loop-worksheets.html)

Steve[_35_]

Loop worksheets
 
I want to have a loop

For loopnum = 1 To 10

In the loop I want to create a new worksheet in each
loop, name the sheet the sheets number spelled out
("one", "two", "three" ...) and write the name of the
sheet in cell A1 of each sheet.

How do I do that ?

Thanks
Steve

Vasant Nanavati

Loop worksheets
 
Something like:

Sub NameWorksheets()
Dim wsNames As Variant, loopnum As Integer, ws As Worksheet
wsNames = _
Array("One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight",
"Nine", "Ten")
For loopnum = 9 To 0 Step -1
Set ws = Worksheets.Add(After:=Worksheets(1))
With ws
.Name = wsNames(loopnum)
.Range("A1") = ws.Name
End With
Next
End Sub

--

Vasant




"Steve" wrote in message
...
I want to have a loop

For loopnum = 1 To 10

In the loop I want to create a new worksheet in each
loop, name the sheet the sheets number spelled out
("one", "two", "three" ...) and write the name of the
sheet in cell A1 of each sheet.

How do I do that ?

Thanks
Steve




No Name

Loop worksheets
 
If it is easier, it would be helpful for me to know how
to do something like name the new sheets all the same
thing with a number after them, like: results1,
results2, results3, ..., results10 and put the number of
the sheet in cell A1.

-----Original Message-----
I want to have a loop

For loopnum = 1 To 10

In the loop I want to create a new worksheet in each
loop, name the sheet the sheets number spelled out
("one", "two", "three" ...) and write the name of the
sheet in cell A1 of each sheet.

How do I do that ?

Thanks
Steve
.


JON JON

Loop worksheets
 
Hello Steve,

Is this what you want?

Sub testme()
For loopnum = 1 To 10
ActiveWorkbook.Sheets.Add after:=Sheets(Sheets.Count)
With ActiveSheet
Select Case loopnum
Case 1
.Name = "One"
Case 2
.Name = "Two"
'and so on
End Select
End With
Next loopnum
End Sub

Regards,

Jon-jon

"Steve" wrote in message
...
I want to have a loop

For loopnum = 1 To 10

In the loop I want to create a new worksheet in each
loop, name the sheet the sheets number spelled out
("one", "two", "three" ...) and write the name of the
sheet in cell A1 of each sheet.

How do I do that ?

Thanks
Steve





All times are GMT +1. The time now is 09:47 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com