Create new sheet on a specific tab

cccbzg

Board Regular
Joined
Oct 5, 2014
Messages
68
Office Version
  1. 365
Platform
  1. Windows
Hi,

This code combines all of the worksheets in a workbook and creates a summary sheet. It works fine but the summary sheet winds up in the middle (sort of) of the other tabs. Not only don't I know why it winds up there, I can't quite figure out how to place the new sheet on a particular tab, like Sheet1.

Any suggestions?

I'm always so impressed with and appreciative of the help I get from this forum.

Many thanks,
Bonnie


' Delete the summary sheet if it exists.
Application.DisplayAlerts = False
On Error Resume Next
ActiveWorkbook.Worksheets("RDBMergeSheet").Delete
On Error GoTo 0
Application.DisplayAlerts = True

' Add a new summary worksheet.
Set DestSh = ActiveWorkbook.Worksheets.Add
DestSh.Name = "RDBMergeSheet"

' Loop through all worksheets and copy the data to the
' summary worksheet.
For Each sh In ActiveWorkbook.Worksheets
If sh.Name <> DestSh.Name Then

' Find the last row with data on the summary worksheet.
Last = LastRow(DestSh)

' Specify the range to place the data.
Set CopyRng = sh.Range("A140:EO140")

' Test to see whether there are enough rows in the summary
' worksheet to copy all the data.
If Last + CopyRng.Rows.Count > DestSh.Rows.Count Then
MsgBox "There are not enough rows in the " & _
"summary worksheet to place the data."
GoTo ExitTheSub
End If

' This statement copies values and formats from each
' worksheet.
CopyRng.Copy
With DestSh.Cells(Last + 1, "A")
.PasteSpecial xlPasteValues
.PasteSpecial xlPasteFormats
Application.CutCopyMode = False
End With

'
' originating Sheet name in the H column.
DestSh.Cells(Last + 1, "EQ").Resize(CopyRng.Rows.Count).Value = sh.Name

End If
Next
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
To create the new sheet as the 1st sheet, change this...

Set DestSh = ActiveWorkbook.Worksheets.Add(Before:=Sheets(1))
 
Upvote 0
This code combines all of the worksheets in a workbook and creates a summary sheet. It works fine but the summary sheet winds up in the middle (sort of) of the other tabs. Not only don't I know why it winds up there, I can't quite figure out how to place the new sheet on a particular tab, like Sheet1.

Any suggestions?

Code:
    ' Add a new summary worksheet.
    Set DestSh = ActiveWorkbook.Worksheets.Add[B][COLOR="#FF0000"](Before:=Sheets(1))[/COLOR][/B]
    DestSh.Name = "RDBMergeSheet"
Add the part I show in red above to place the sheet at the beginning of the sheets.
 
Upvote 0
My thanks to both Rick and AlphaFrog. That worked like a charm!
It's a good to know little tidbit.

Always grateful,
Bonnie
 
Upvote 0

Forum statistics

Threads
1,216,192
Messages
6,129,434
Members
449,509
Latest member
ajbooisen

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top