Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default test if a sheet exist (with the name) ?

Hi,

i'm looking for a way to know if a sheet exist with the name (ex : "01J")
if it doesn't exist , i have to create it ...

thanks for any help.
------
Laurent.




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default test if a sheet exist (with the name) ?

Laurent,

Here is some code

Sub test()

If Not SheetExists("ABC") Then
ActiveWorkbook.Worksheets.Add after:=Worksheets(Worksheets.Count)
ActiveSheet.Name = "ABC"
End If

End Sub
Function SheetExists(Filename As String)
Dim oSh As Worksheet
On Error Resume Next
Set oSh = ActiveWorkbook.Worksheets(Filename)
On Error GoTo 0
SheetExists = Not oSh Is Nothing
End Function



--

HTH

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

"LoloSoft" wrote in message
...
Hi,

i'm looking for a way to know if a sheet exist with the name (ex : "01J")
if it doesn't exist , i have to create it ...

thanks for any help.
------
Laurent.






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default test if a sheet exist (with the name) ?

Hi Laurent,

Something like this will work:

Public Function gbWSExists(rsShtName As String) As Boolean
On Error Resume Next
gbWSExists = Len(Worksheets(rsShtName).Name)
On Error GoTo 0
End Function

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


LoloSoft wrote:
Hi,

i'm looking for a way to know if a sheet exist with the name (ex :
"01J") if it doesn't exist , i have to create it ...

thanks for any help.
------
Laurent.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default test if a sheet exist (with the name) ?

I am making the assumption 01J would be a worksheet.

Dim sh as Worksheet
On error resume next
set sh = Worksheets("01J")
On Error goto 0
if sh is nothing then
worksheets.Add(After:=Worksheets(worksheets.count) ).Name ="01J"
set sh = worksheets("01J")
End if

--
Regards,
Tom Ogilvy

"LoloSoft" wrote in message
...
Hi,

i'm looking for a way to know if a sheet exist with the name (ex : "01J")
if it doesn't exist , i have to create it ...

thanks for any help.
------
Laurent.








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
Want a trace a same values exist in two different sheet Mukesh Excel Worksheet Functions 2 April 23rd 09 12:56 PM
verify if spesific sheet exist Miri Excel Discussion (Misc queries) 3 February 26th 07 01:04 PM
VBA: Make a new sheet if it doesn't exist PaulW Excel Discussion (Misc queries) 2 May 8th 06 03:45 PM
VBA, Make a new sheet if it doesn't exist PaulW Excel Discussion (Misc queries) 1 May 5th 06 05:25 PM
Does sheet exist? Sean Evanovich Excel Programming 2 November 19th 03 02:30 PM


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