Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
creating sheets | Excel Discussion (Misc queries) | |||
Creating new sheets | Excel Discussion (Misc queries) | |||
Dynamically Creating Sheets | Excel Programming | |||
Creating new sheets (more detailed) | Excel Programming | |||
Creating New sheets | Excel Programming |