Selecting a newly added and named worksheet

L

Lynz

Hi, thanks to the very helpful people on here and the net i have the
following code for inserting a new sheet , formatting it naming it etc.
At the end of the code the "owks" has a new name and the "iwks" is
cleared for reuse.
What I need to know is how to activate the newly named worksheet after
all this is done so that it is the one in view. seems simple but I cant
quite get it. Here is the relevant (I think) part of the code.
Thank you for any assistance.
ps the new worksheet has a new name each time.

With oWks.PageSetup
'added margins??
.LeftMargin = Application.InchesToPoints(0.5)
.RightMargin = Application.InchesToPoints(0.1)
.TopMargin = Application.InchesToPoints(0.6)
.BottomMargin = Application.InchesToPoints(0.7)
.HeaderMargin = Application.InchesToPoints(0.4)
.FooterMargin = Application.InchesToPoints(0.5)
.CenterHeader = Range("A2").Value
.CenterFooter = "Page &P of &N"

End With
On Error Resume Next
oWks.Name = Range("A2").Value


'Clear the ws Cat2 so can use it again
iWks.Select
Cells.Select
Selection.Clear
Range("a1").Select

End Sub
 
L

Lynz

You don't have to select a sheet in order to clear it.
So... iWks.Cells.Clear ...is all you need and the newly added sheet will remain the
active sheet.

Thank you so much. I will try that. I knew it had to be something simple
and trying to select owks didnt work as it was renamed.
Cheers Lyn
 

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