Control the insert of a new sheet.

  • Thread starter Thread starter Question_123
  • Start date Start date
Q

Question_123

Hi group,

I have searched this group already with no real defining answer to my
question. I have a macro that reads a sheet of infomation and creates
new sheets. Is there a way to control where the sheet is inserted. The
default is "before". I want it to show up "after". I have included
the code I use to create the additional worksheets. Any help would be
appreciated.

Sub Make_Reports()

Dim iReport As Long
Dim lRow As Long
Dim i As Integer
Dim wsReport As Worksheet
Dim wsData As Worksheet

iReport = 1
lRow = 1
Set wsData = ActiveSheet
Application.ScreenUpdating = False

Do While Not IsEmpty(wsData.Cells(lRow, 1))

'add new worksheet for new report
Set wsReport = Worksheets.Add
wsReport.Name = wsData.Cells(lRow, 2)

'copy data (26 rows * 9 columns)
wsData.Cells(lRow, 1).Resize(26, 9).Copy _
Destination:=wsReport.Range("A5")

'Increment Counter
lRow = lRow + 26

Loop

End Sub
 
Set wsReport = Worksheets.Add( After:=worksheets(worksheets.count))

as an example.
 

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