Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add sheet in excel

Status
Not open for further replies.

Phailak

Programmer
Joined
Apr 10, 2001
Messages
142
Location
CA
Hail,

This should be easy, when you add a sheet to an existing excel workbook, what code can make sure it is the last one to the right of the other sheets

I know you can:
Obj.Sheets("04-13").Move 'After:=Sheets(121)

But how do I know 121 is the last sheet?

Phailak
 
msgbox obj.MsgBox Sheets.Count
?
ide
 
i'm wrong
msgbox MsgBox obj.Sheets.Count
:)
?
 
MsgBox obj.Sheets.Count
... :-(
:)
 
Ok that gives me the number of sheets in total but what if some were removed, I want to move my new sheet at the end of all the others

Phailak
 
sorry, i dont understand
 
Here's an example of what I mean...

Let's say you have a xls file with 7 sheets named X1, X2, X3...

Now you delete X2 and X5 so that you have 5 sheets left X1, X3, X4, X6 and X7

After, I add another sheet, X8, but want to make sure it appears after X7 at the bottom screen, so I can't use count because I need the number of the identifing sheet as so

Obj.Sheets("X8").Move After:=Sheets(X7)

What I need is to know how to specify X7 IS my last sheet?

Better?
 

Phailak
:

This will work.

Sheets("X8").Move After:=Sheets(Sheets.Count)

Regards,

LoNeRaVeR
 
Thanx I'll try it Monday

Phailak
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top