New Sheet

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello

How can I add a new sheet to a workbook using vba and call
it a specific name (not sheet1). And if that name already
exist in a sheet for the workbook call it that name + 1.
 
Hi
try
....
dim wks as worksheet
set wks = worksheets.add
wks.name="myname"
 
Prior to adding the sheet, get the name. Then go through
the worksheets collection testing for the name property.
Something like:
For each wks in Thisworkbook.Worksheets
If wks.Name=strNewName then
strNewName = some other name
blnDuplicate = True
End If
Next wks
If blnDuplicate = False Then
'Add your new sheet and rename it.
End If

Good luck.
Geof.
 
Hello,

I get an error if the workbook already contains the
worksheet "myname". How do I title the sheet "myname1" if
it already exists or "myname2" if they both do ... etc.

Thanks for your help.
 

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