Loop worksheets

S

Steve

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
 
V

Vasant Nanavati

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
 
G

Guest

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.
 
J

JON JON

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
 

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

Top