Moving Sheets within a workbook


G

Guest

I have a function that adds a new work when needed

'Add A New Sheet
ActiveWorkbook.Sheets.Add

The problem is that when the sheet is inserted it is placed at the beginning
of the workbook. Sheet2 will appear before Sheet1.

I want to automate the process of moving Sheet2 after Sheet1 and all
subsequent Sheets (3, 4, 5 ...)

Sheets("Sheet2").Select
Sheets("Sheet2").Move After:=Sheets(1)

How do I use a counter/variable in place of the "2" so that each time I call
the "ActiveWorkbook.Sheets.Add" it will add the new Sheet to the end?

Thanks
 
Ad

Advertisements

B

Bob Phillips

With ActiveWorkbook
.Worksheets.Add after:=.Worksheets(.Worksheets.Count)
End With


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
G

Guest

What I have is if a function is called:

If " some function" Then
ActiveWorkbook.Sheets.Add
End If

Where in the above statement do I insert your statements?

With ActiveWorkbook
.Worksheets.Add after:=.Worksheets(.Worksheets.Count)
End With

Dan


ActiveWorkbook.Sheets.Add
 
B

Bob Phillips

Instead of this

ActiveWorkbook.Sheets.Add


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
Ad

Advertisements

G

Guest

Thanks. Works great.

Bob Phillips said:
Instead of this

ActiveWorkbook.Sheets.Add


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
Ad

Advertisements


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