Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Creating Sheets in VBA


I want to create a set of sheets that are basically the same, except for
a few changes. But I may need to create new ones on the fly, and I was
curious if there was a way to check if the sheet exists and if it does
go to that sheet, and if it doesn't create a new one. I was planning
on using a naming configuration of ScoringSheet_x and the x would be
selected by the user.


--
cmk18
------------------------------------------------------------------------
cmk18's Profile: http://www.excelforum.com/member.php...fo&userid=6047
View this thread: http://www.excelforum.com/showthread...hreadid=386196

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Creating Sheets in VBA


Good evening Cmk18

If you try to navigate to a non existent sheet in VBA an error will be
thrown up. Why not trap the error (such as On Error Goto NewSheet) and
then at the NewSheet: label, create the new sheet. If an error doesn't
occur, the sheet exists and you can Exit Sub.

HTH

DominicB


--
dominicb
------------------------------------------------------------------------
dominicb's Profile: http://www.excelforum.com/member.php...o&userid=18932
View this thread: http://www.excelforum.com/showthread...hreadid=386196

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Creating Sheets in VBA

This is from Chip Pearson:

Function WorksheetExists(SheetName As Variant, _
Optional WhichBook As Workbook) As Boolean
'from Chip Pearson
Dim WB As Workbook
Set WB = IIf(WhichBook Is Nothing, ThisWorkbook, WhichBook)
On Error Resume Next
WorksheetExists = CBool(Len(WB.Worksheets(SheetName).Name) 0)
End Function

And you could use that function in your code like:

if worksheetexists("mysheetname",activeworkbook) then
'sheet exists
else
'add the sheet and name it
end if



cmk18 wrote:

I want to create a set of sheets that are basically the same, except for
a few changes. But I may need to create new ones on the fly, and I was
curious if there was a way to check if the sheet exists and if it does
go to that sheet, and if it doesn't create a new one. I was planning
on using a naming configuration of ScoringSheet_x and the x would be
selected by the user.

--
cmk18
------------------------------------------------------------------------
cmk18's Profile: http://www.excelforum.com/member.php...fo&userid=6047
View this thread: http://www.excelforum.com/showthread...hreadid=386196


--

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
creating sheets CSWP Excel Discussion (Misc queries) 1 June 15th 09 10:37 PM
Creating new sheets Hru48 Excel Discussion (Misc queries) 10 September 28th 05 04:26 PM
Dynamically Creating Sheets Todd Huttenstine[_2_] Excel Programming 1 November 3rd 03 03:35 AM
Creating new sheets (more detailed) Todd Huttenstine[_2_] Excel Programming 1 November 3rd 03 03:33 AM
Creating New sheets Jason[_21_] Excel Programming 4 September 1st 03 05:36 AM


All times are GMT +1. The time now is 07:17 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"