ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   A simple problem... (https://www.excelbanter.com/excel-programming/286188-simple-problem.html)

Chris Gorham[_3_]

A simple problem...
 
Hi,

just trying to add a worksheet behind an existing one and
naming it.
trying this:

Sheets.Add Type:=Worksheet, count:=1, after:=Sheets
(Origsheet)

but I'd like to assign a name to it (in the same
statement...must be possible..!!)

Thks

Chris

J.E. McGimpsey

A simple problem...
 
One way:

Worksheets.Add(After:=Sheets(Origsheet)).Name = "Fred"

Where OrigSheet contains either an index number or a sheetname as a
string.

In article ,
"Chris Gorham" wrote:

Hi,

just trying to add a worksheet behind an existing one and
naming it.
trying this:

Sheets.Add Type:=Worksheet, count:=1, after:=Sheets
(Origsheet)

but I'd like to assign a name to it (in the same
statement...must be possible..!!)

Thks

Chris


Brad Vontur

A simple problem...
 
Try:

Private Sub CommandButton1_Click()
Dim shtNew As Worksheet
Set shtNew = ActiveWorkbook.Worksheets.Add
(After:=Worksheets(Worksheets.Count))
shtNew.Name = "New Sheet"
End Sub

HTH.

-Brad

-----Original Message-----
Hi,

just trying to add a worksheet behind an existing one and
naming it.
trying this:

Sheets.Add Type:=Worksheet, count:=1, after:=Sheets
(Origsheet)

but I'd like to assign a name to it (in the same
statement...must be possible..!!)

Thks

Chris
.



All times are GMT +1. The time now is 12:20 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com