Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 397
Default If the sheet exists...., then



HI there,

Ive got VB runing that creates a sheet called master. Problem is users
sometimes (and in certain cirumstances correctly) re-run the macro, but
then I get an error cause the sheets exists. So Im lookin for VB that
says if sheet Master exists, bring a a message that says "sheet exists,
do u really want to run Macro?" - if you say yes it will delete the
sheet master, and then run the macro, if you say no it will stop!

Ideas welcomed!!!

Regards

D

*** Sent via Developersdex http://www.developersdex.com ***
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default If the sheet exists...., then

One way:


Dim ws As Worksheet
Dim nResponse As Long
On Error Resume Next
Set ws = ActiveWorkbook.Sheets("Master")
On Error GoTo 0
If Not ws Is Nothing Then
nResponse = MsgBox( _
Prompt:="Sheet exists." & vbNewLine & vbNewLine & _
"Do you really want to run the macro?", _
Title:="Error", _
Buttons:=vbYesNo)
If nResponse = vbNo Then Exit Sub
Application.DisplayAlerts = False
ws.Delete
Application.DisplayAlerts = True
End If


In article ,
Darin Kramer wrote:

HI there,

Ive got VB runing that creates a sheet called master. Problem is users
sometimes (and in certain cirumstances correctly) re-run the macro, but
then I get an error cause the sheets exists. So Im lookin for VB that
says if sheet Master exists, bring a a message that says "sheet exists,
do u really want to run Macro?" - if you say yes it will delete the
sheet master, and then run the macro, if you say no it will stop!

Ideas welcomed!!!

Regards

D

*** Sent via Developersdex http://www.developersdex.com ***

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default If the sheet exists...., then

Possibly:-

Sub marine()
Dim sh As Worksheet, flg As Boolean
For Each sh In Worksheets
If sh.Name = "Master" Then flag = True: Exit For
Next
If flag = True Then
response = MsgBox("That sheet exists. Continue", vbYesNo)
If response = vbYes Then
ActiveSheet.Delete
Sheets.Add.Name = "Master"
End If
End If
End Sub

Mike

"Darin Kramer" wrote:



HI there,

Ive got VB runing that creates a sheet called master. Problem is users
sometimes (and in certain cirumstances correctly) re-run the macro, but
then I get an error cause the sheets exists. So Im lookin for VB that
says if sheet Master exists, bring a a message that says "sheet exists,
do u really want to run Macro?" - if you say yes it will delete the
sheet master, and then run the macro, if you say no it will stop!

Ideas welcomed!!!

Regards

D

*** Sent via Developersdex http://www.developersdex.com ***

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default If the sheet exists...., then

Dim sh as Worksheet
Dim ans as Long
On Error Resume Next
set sh = Worksheets("Master")
On error goto 0
if not sh is nothing then
ans = MsgBox("Master Exists - " & vbNewlIne & _
" Hit OK to delete Master and continue" & _
vbNewLine & " Hit Cancel to quit", _
Buttons:= vbOKCancel)
if ans = vbCancel then exit sub
Application.DisplayAlerts = False
sh.Delete
Application.DisplayAlerts = True
end if
' at this point, Master does not exist.

--
Regards,
Tom Ogilvy





"Darin Kramer" wrote:



HI there,

Ive got VB runing that creates a sheet called master. Problem is users
sometimes (and in certain cirumstances correctly) re-run the macro, but
then I get an error cause the sheets exists. So Im lookin for VB that
says if sheet Master exists, bring a a message that says "sheet exists,
do u really want to run Macro?" - if you say yes it will delete the
sheet master, and then run the macro, if you say no it will stop!

Ideas welcomed!!!

Regards

D

*** Sent via Developersdex http://www.developersdex.com ***

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default If the sheet exists...., then

Missed a line

Sub marine()
Dim sh As Worksheet, flg As Boolean
For Each sh In Worksheets
sh.Select
If sh.Name = "Master" Then flag = True: Exit For
Next
If flag = True Then
response = MsgBox("That sheet exists. Continue", vbYesNo)
If response = vbYes Then
ActiveSheet.Delete
Sheets.Add.Name = "Master"
End If
End If
End Sub

"Darin Kramer" wrote:



HI there,

Ive got VB runing that creates a sheet called master. Problem is users
sometimes (and in certain cirumstances correctly) re-run the macro, but
then I get an error cause the sheets exists. So Im lookin for VB that
says if sheet Master exists, bring a a message that says "sheet exists,
do u really want to run Macro?" - if you say yes it will delete the
sheet master, and then run the macro, if you say no it will stop!

Ideas welcomed!!!

Regards

D

*** Sent via Developersdex http://www.developersdex.com ***



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 397
Default If the sheet exists...., then


Thanks!!!!


*** Sent via Developersdex http://www.developersdex.com ***
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
If sheet exists, then... Darin Kramer Excel Programming 9 September 12th 06 01:22 PM
Deleting a sheet if it exists? drucey[_5_] Excel Programming 5 March 17th 06 02:53 PM
check if the sheet/tag exists Alex Excel Worksheet Functions 2 March 14th 06 08:58 PM
Sheet name already exists eddie_zoom Excel Discussion (Misc queries) 1 March 11th 05 02:53 PM
How can I know if a sheet exists ? Ben.C Excel Programming 3 December 29th 03 09:36 AM


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