Renaming multiple sheets in Excel

Caporegime
Joined
28 Oct 2003
Posts
32,382
Location
Chestershire
Hi, wonder if anyone can help me out here.

I have an Excel worksheet which consists of about 20-odd sheets. What I would like to do is use a bit of VBA code to rename them in sequential order. So it selects the first sheet and gives it a name of "1", then the next sheet becomes "2" and so on until it has done them all...

I guess you need to create a 'for' loop or something and iterate through each sheet but I don't know the commands to do it.
 
I haven't tested it, so it might need some tweaking, but something like this is probably what you need:

Code:
sheetCounter = 1
For Each wrksht In ActiveWorkbook.Worksheets
    wrksht.Name = sheetCounter
    sheetCounter = sheetCounter + 1
Next wrksht
 
You beauty.

Thanks very much. Seems to work perfectly on my little tests - just needed to add a Sub declaration thingy and it was happy!

Cheers.
 
Back
Top Bottom