LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Help in Excel VBA Programing - How to check an Excel Worksheet?

Are you talking about a worksheet function? If so, you are out of luck as
you cannot do that from Excel directly, it has to be from within a macro.

If in VBA this will do it

'-----------------------------------------------------------------
Function SheetExists(Sh As String, _
Optional wb As Workbook) As Boolean
'-----------------------------------------------------------------
Dim oWs As Worksheet
If wb Is Nothing Then Set wb = ActiveWorkbook
On Error Resume Next
SheetExists = CBool(Not wb.Worksheets(Sh) Is Nothing)
If SheetExists Then
Application.DisplayAlerts = False
wb.Worksheets(Sh).Delete
Else
wb.Worksheets.Add.Name = Sh
End If
On Error GoTo 0
End Function


invoked from VBA with a simple

SheetExists "Report"

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"wmcray " wrote in message
...
Hi Bob,

Thanks for your prompt reply.

Please forgive me as I really do not have a lot of programming
knowledge in Excel VBA.

But I really want to write a simple check to see if there is a
worksheet titled "Report". If there is one, please delete the
worksheet, otherwise, add a new one called "Report'.

Therefore, I have figured out the IF, THEN, ElSE statement.

But I don't understand your function call such as where to put the
function and how to incorporate it into my IF, THEN, ELSE statement.

Can you simply provide me a IF statement incorporating the checking
whether a worksheet titled "Report" exists?

Please kindly advise. Thanks


---
Message posted from http://www.ExcelForum.com/



 
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
excel programing rlenz Excel Discussion (Misc queries) 2 April 18th 06 02:41 PM
Programing Outlook using Excel V. Roe Excel Programming 5 July 23rd 04 06:00 PM
programing reference worksheet Alberto Guzman Excel Programming 1 October 19th 03 09:16 PM
help with excel programing drummerboy827[_4_] Excel Programming 1 September 27th 03 03:31 PM
Excel Programing Resources Kirk[_3_] Excel Programming 2 August 8th 03 08:01 PM


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