ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   inserting sheets in excel (https://www.excelbanter.com/excel-programming/325247-inserting-sheets-excel.html)

Neil

inserting sheets in excel
 
I am building an automated macro where depending on a certain conditions a
formatted sheet is inserted and key fields from the master spreadsheet, this
may happen more than once in the spreadsheet. I can do it once, but cannot
find out how to select the last created sheet where I create more than one
sheet so I can insert the default data.

Any help would be appreciated.

thanks
--
neil

Tom Ogilvy

inserting sheets in excel
 
When you create it, it will be the activesheet. It might be useful to
assign it a sequential style unique name at that time.

--
Regards,
Tom Ogilvy

"neil" wrote in message
...
I am building an automated macro where depending on a certain conditions a
formatted sheet is inserted and key fields from the master spreadsheet,

this
may happen more than once in the spreadsheet. I can do it once, but

cannot
find out how to select the last created sheet where I create more than one
sheet so I can insert the default data.

Any help would be appreciated.

thanks
--
neil




Neil

inserting sheets in excel
 
Makes sense, but how do I do it?

thanks

Neil

"Tom Ogilvy" wrote:

When you create it, it will be the activesheet. It might be useful to
assign it a sequential style unique name at that time.

--
Regards,
Tom Ogilvy

"neil" wrote in message
...
I am building an automated macro where depending on a certain conditions a
formatted sheet is inserted and key fields from the master spreadsheet,

this
may happen more than once in the spreadsheet. I can do it once, but

cannot
find out how to select the last created sheet where I create more than one
sheet so I can insert the default data.

Any help would be appreciated.

thanks
--
neil





Dave Peterson[_5_]

inserting sheets in excel
 
dim mstrWks as worksheet
dim newWks as worksheet

set mstrwks = activesheet 'worksheets("sheet99")
set newwks = worksheets.add

Then you can use that newwks variable to do things.

newwks.range("a1").value = "Hey, I just added this sheet"

newwks.name = format(now,"yyyymmdd_hhmmss")
'a nice unique name???

neil wrote:

I am building an automated macro where depending on a certain conditions a
formatted sheet is inserted and key fields from the master spreadsheet, this
may happen more than once in the spreadsheet. I can do it once, but cannot
find out how to select the last created sheet where I create more than one
sheet so I can insert the default data.

Any help would be appreciated.

thanks
--
neil


--

Dave Peterson

Tom Ogilvy

inserting sheets in excel
 
Dim i as Long
Dim sh as Worksheet
i = 0
for each sh in Worksheets
if lcase(Left(sh.name,12)) = "myaddedsheet" then
i = i + 1
Next
End Sub
worksheets.add After:=worksheets(worksheets.count)
Activesheet.Name = "MyAddedSheet" & i + 1

--
Regards,
Tom Ogilvy

"neil" wrote in message
...
Makes sense, but how do I do it?

thanks

Neil

"Tom Ogilvy" wrote:

When you create it, it will be the activesheet. It might be useful to
assign it a sequential style unique name at that time.

--
Regards,
Tom Ogilvy

"neil" wrote in message
...
I am building an automated macro where depending on a certain

conditions a
formatted sheet is inserted and key fields from the master

spreadsheet,
this
may happen more than once in the spreadsheet. I can do it once, but

cannot
find out how to select the last created sheet where I create more than

one
sheet so I can insert the default data.

Any help would be appreciated.

thanks
--
neil







Jim May

inserting sheets in excel
 
I had to change lines:

Next
End Sub

to

End If
Next

Right?


"Tom Ogilvy" wrote in message
...
Dim i as Long
Dim sh as Worksheet
i = 0
for each sh in Worksheets
if lcase(Left(sh.name,12)) = "myaddedsheet" then
i = i + 1
Next
End Sub
worksheets.add After:=worksheets(worksheets.count)
Activesheet.Name = "MyAddedSheet" & i + 1

--
Regards,
Tom Ogilvy

"neil" wrote in message
...
Makes sense, but how do I do it?

thanks

Neil

"Tom Ogilvy" wrote:

When you create it, it will be the activesheet. It might be useful to
assign it a sequential style unique name at that time.

--
Regards,
Tom Ogilvy

"neil" wrote in message
...
I am building an automated macro where depending on a certain

conditions a
formatted sheet is inserted and key fields from the master

spreadsheet,
this
may happen more than once in the spreadsheet. I can do it once,

but
cannot
find out how to select the last created sheet where I create more

than
one
sheet so I can insert the default data.

Any help would be appreciated.

thanks
--
neil








Tom Ogilvy

inserting sheets in excel
 
As Jim said (thanks)

Dim i as Long
Dim sh as Worksheet
i = 0
for each sh in Worksheets
if lcase(Left(sh.name,12)) = "myaddedsheet" then
i = i + 1
end if
Next
worksheets.add After:=worksheets(worksheets.count)
Activesheet.Name = "MyAddedSheet" & i + 1

--
Regards,


"Jim May" wrote in message
news:vWXYd.75670$%U2.8675@lakeread01...
I had to change lines:

Next
End Sub

to

End If
Next

Right?


"Tom Ogilvy" wrote in message
...
Dim i as Long
Dim sh as Worksheet
i = 0
for each sh in Worksheets
if lcase(Left(sh.name,12)) = "myaddedsheet" then
i = i + 1
Next
End Sub
worksheets.add After:=worksheets(worksheets.count)
Activesheet.Name = "MyAddedSheet" & i + 1

--
Regards,
Tom Ogilvy

"neil" wrote in message
...
Makes sense, but how do I do it?

thanks

Neil

"Tom Ogilvy" wrote:

When you create it, it will be the activesheet. It might be useful

to
assign it a sequential style unique name at that time.

--
Regards,
Tom Ogilvy

"neil" wrote in message
...
I am building an automated macro where depending on a certain

conditions a
formatted sheet is inserted and key fields from the master

spreadsheet,
this
may happen more than once in the spreadsheet. I can do it once,

but
cannot
find out how to select the last created sheet where I create more

than
one
sheet so I can insert the default data.

Any help would be appreciated.

thanks
--
neil











All times are GMT +1. The time now is 08:34 AM.

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