Adding & Naming Worksheets in a macro

  • Thread starter Thread starter John
  • Start date Start date
J

John

I'm writing a macro which should create a new worksheet,
then transfer data from an existing worksheet to the new
worksheet.

My problem is that the name of the new worksheet is
defined when worksheet is created. Its name is random,
depending on the number of existing worksheets at the
time. I want the macro to be general, working when there
are any number of sheets in the workbook.

I can't figure out how to change the name of the new
worksheet to some contstant name, so that I can refer to
then it and know the macro will work for an arbitrary
worksheet.

thanks
John
 
Here's some code from the Visual Basic object browser
help screen for Class Workbooks, Member Worksheets
 
John ,

You can name the worksheet as you add it with

Worksheets.Add(after:=Worksheets(Worksheets.Count)).Name = "myWorksheet"

this then becomes the activesheet, and you can refer to it as such

Activesheet.Activate

--

HTH

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