Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 173
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 173
Default 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




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 430
Default 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









  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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









  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default 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
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Inserting sheets into Excel workbook Sally Excel Discussion (Misc queries) 6 January 28th 10 08:05 PM
Inserting Sheets from multiple files fgwiii Excel Discussion (Misc queries) 2 November 2nd 05 08:47 PM
Updating, Deleting and inserting rows over two Excel Sheets Dilip Mistry Excel Worksheet Functions 0 July 25th 05 07:09 PM
Inserting Sheets and Naming Dan Gesshel Excel Programming 5 April 15th 04 01:52 AM
Inserting and arranging sheets Andrea[_7_] Excel Programming 1 November 4th 03 01:02 AM


All times are GMT +1. The time now is 02:23 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"