Naming a new sheet.

R

Rich Cooper

I am adding a new sheet and trying to name that sheet.
I can add a sheet and i can name a sheet using vba
But when i try to do them together it doesn't work.
I can add a sheet. Then i have to fugure out what it is named and then i
can change the name. Is there a simplier way to add a new sheet to a
workbook and change the name?
 
B

Bob Phillips

You don't have to figure out what the name is, as the sheet just added
becomes the activesheet. So you could use

Worksheets.Add
Activesheet.Name = "Rich"

or you could use object variables

Set newSheet = Worksheets.Add
newSheet.Name = "Rich"

or even create and name in one go

Worksheets.Add.Name = "Rich"

My preference is usually the second, as you have a handle to the worksheet
that you can use at any time.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Top