Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 492
Default Does a worksheet exist?

Hi All,
I have a file that records defects on a fleet of vehicles with a macro in it
which produces a list of repeat defects in the last 28 days on demand when
the vehicle comes up for servicing..
This macro names the worksheet as the name of the vehicle, for arguments
sake, call it 'Truck25'.
Sometimes a user will invoke this macro when a worksheet called 'Truck25'
already exists.
I've used the error handler facility within the macro code to pop up a
message box to inform the user that the sheet name already exists, delete
the new sheet and exit the sub.
I need to give some kind of warning that the macro wont work because the
people that use it are not computer buffs, just exiting generates a lot of
phone calls!
My question is, is there any way to determine whether a sheet named
'Truck25' exists already? If so I can modify the code to delete it before
another one is created and thus avoid the error and the need for a message
box,
TIA,
Regards,
Alan.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Does a worksheet exist?

I don't follow the question completely but here is a function that will tell
you if a sheet exists in a given workbook...

Public Function SheetExists(SName As String, _
Optional ByVal Wb As Workbook) As Boolean
'Chip Pearson
On Error Resume Next
If Wb Is Nothing Then Set Wb = ThisWorkbook
SheetExists = CBool(Len(Wb.Sheets(SName).Name))
End Function
--
HTH...

Jim Thomlinson


"Alan" wrote:

Hi All,
I have a file that records defects on a fleet of vehicles with a macro in it
which produces a list of repeat defects in the last 28 days on demand when
the vehicle comes up for servicing..
This macro names the worksheet as the name of the vehicle, for arguments
sake, call it 'Truck25'.
Sometimes a user will invoke this macro when a worksheet called 'Truck25'
already exists.
I've used the error handler facility within the macro code to pop up a
message box to inform the user that the sheet name already exists, delete
the new sheet and exit the sub.
I need to give some kind of warning that the macro wont work because the
people that use it are not computer buffs, just exiting generates a lot of
phone calls!
My question is, is there any way to determine whether a sheet named
'Truck25' exists already? If so I can modify the code to delete it before
another one is created and thus avoid the error and the need for a message
box,
TIA,
Regards,
Alan.



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
Does worksheet exist BB Ivan Excel Discussion (Misc queries) 1 January 29th 09 10:04 PM
File opens as worksheet.xls:1 and worksheet.xls:2. Only one exist Dave the wave[_2_] Excel Programming 5 January 30th 06 11:28 PM
Does a worksheet exist? papa jonah Excel Programming 2 January 5th 06 06:20 PM
Does Worksheet Exist BillCPA Excel Discussion (Misc queries) 5 April 19th 05 11:22 PM
Does a worksheet exist Kaval[_2_] Excel Programming 3 May 31st 04 07:21 AM


All times are GMT +1. The time now is 11:26 AM.

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

About Us

"It's about Microsoft Excel"