Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
KtM KtM is offline
external usenet poster
 
Posts: 13
Default Checking for existing worksheet name

Morning!
I am doing a little program that would fetch information to a set of
sheets, which works OK now.
Problem is with checking if the data has been previously fetched, then
it should overwrite existing data instead of creating a new set.
How do you check if exists stuff in excel.

Basic idea.
If exists (name) then
write to name
else
new sheet with (name)

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default Checking for existing worksheet name

I found this UDF in the forum, I forgot the name of the author, sorry!

Public Function WSExist(wsname As String) As Boolean
'returns true if worksheet exists in the active workbook
Dim objWorksheet As Object
On Error Resume Next
WSExist = False
Set objWorksheet = ActiveWorkbook.Sheets(wsname )
If Err = 0 Then WSExist = True
End Function


Regards,
Stefi

€˛KtM€¯ ezt Ć*rta:

Morning!
I am doing a little program that would fetch information to a set of
sheets, which works OK now.
Problem is with checking if the data has been previously fetched, then
it should overwrite existing data instead of creating a new set.
How do you check if exists stuff in excel.

Basic idea.
If exists (name) then
write to name
else
new sheet with (name)


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Checking for existing worksheet name

Here is a sheet check function that you can incorporate

'-----------------------------------------------------------------
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)
On Error GoTo 0
End Function


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"KtM" wrote in message
oups.com...
Morning!
I am doing a little program that would fetch information to a set of
sheets, which works OK now.
Problem is with checking if the data has been previously fetched, then
it should overwrite existing data instead of creating a new set.
How do you check if exists stuff in excel.

Basic idea.
If exists (name) then
write to name
else
new sheet with (name)



  #4   Report Post  
Posted to microsoft.public.excel.programming
KtM KtM is offline
external usenet poster
 
Posts: 13
Default Checking for existing worksheet name

Thank you for both replies, both work nicely. Thanks!

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
Checking for the existence of a worksheet Allen Excel Discussion (Misc queries) 1 January 20th 10 06:57 PM
Checking to see if a worksheet exists Raman325[_27_] Excel Programming 7 August 19th 05 06:36 PM
How do I conditionally build worksheet from existing worksheet? Bob G Excel Discussion (Misc queries) 1 July 3rd 05 06:40 PM
Checking whether a worksheet exist or not ajitpalsingh200[_18_] Excel Programming 0 November 10th 04 05:44 AM
Checking whether a worksheet exist or not ajitpalsingh200[_17_] Excel Programming 4 November 9th 04 01:30 PM


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