Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Checking a worksheet is present

I have a macro that relies on a worksheet being present, however if the sheet
is missing I need to reply with a message box to tell the person to copy in
the worksheet

If Worksheet ("data") = False Then
MsgBox "You need to copy of the data worksheet."
Else
Continue with Macro
End If

TIA
mmc308


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 461
Default Checking a worksheet is present

Try something like this

Sub data()

For ws = 1 To Worksheets.Count

If Worksheets(ws).Name = "Data" Then GoTo ContinueMacro

Next ws

MsgBox ("You need to copy Data Worksheet")

ContinueMacro:
"ENTER REST OF MACRO HERE"

End Sub

"mmc308" wrote:

I have a macro that relies on a worksheet being present, however if the sheet
is missing I need to reply with a message box to tell the person to copy in
the worksheet

If Worksheet ("data") = False Then
MsgBox "You need to copy of the data worksheet."
Else
Continue with Macro
End If

TIA
mmc308


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Checking a worksheet is present

Dim TestWks as worksheet

set testwks = nothing
on error resume next
set testwks = worksheets("data")
on error goto 0

if testwks is nothing then
msgbox "your message here
else
'keep going...
end if

mmc308 wrote:

I have a macro that relies on a worksheet being present, however if the sheet
is missing I need to reply with a message box to tell the person to copy in
the worksheet

If Worksheet ("data") = False Then
MsgBox "You need to copy of the data worksheet."
Else
Continue with Macro
End If

TIA
mmc308


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 461
Default Checking a worksheet is present

Keep in mind, that if Data sheet isn't present, you have to create another
line after the msgbox if you don't want the macro to continue. One way is to
put GoTo NoData

Then right before End Sub

Put the Line NoData: MsgBox("No Data Worksheet")
End Sub

Whatever you like.... theres tons of ways to do it.

"mmc308" wrote:

I have a macro that relies on a worksheet being present, however if the sheet
is missing I need to reply with a message box to tell the person to copy in
the worksheet

If Worksheet ("data") = False Then
MsgBox "You need to copy of the data worksheet."
Else
Continue with Macro
End If

TIA
mmc308


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Checking a worksheet is present

One way:

Dim ws As Worksheet
On Error Resume Next
Set ws = ActiveWorkbook.Worksheets("data")
On Error GoTo 0
If ws Is Nothing Then
MsgBox "You need to copy of the data worksheet."
Else
'Continue with Macro
End If



In article ,
mmc308 wrote:

I have a macro that relies on a worksheet being present, however if the sheet
is missing I need to reply with a message box to tell the person to copy in
the worksheet

If Worksheet ("data") = False Then
MsgBox "You need to copy of the data worksheet."
Else
Continue with Macro
End If

TIA
mmc308



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Checking a worksheet is present

This worked

Many Thanks for your help

mmc308

"JE McGimpsey" wrote:

One way:

Dim ws As Worksheet
On Error Resume Next
Set ws = ActiveWorkbook.Worksheets("data")
On Error GoTo 0
If ws Is Nothing Then
MsgBox "You need to copy of the data worksheet."
Else
'Continue with Macro
End If



In article ,
mmc308 wrote:

I have a macro that relies on a worksheet being present, however if the sheet
is missing I need to reply with a message box to tell the person to copy in
the worksheet

If Worksheet ("data") = False Then
MsgBox "You need to copy of the data worksheet."
Else
Continue with Macro
End If

TIA
mmc308


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
How to present a form instead of the worksheet Parvaiz Excel Discussion (Misc queries) 2 February 20th 09 04:45 PM
Checking whether a value in a list is present in a second list [email protected] Excel Discussion (Misc queries) 5 June 1st 07 02:30 PM
Selecting a row from one worksheet if it is present in another [email protected] Excel Programming 5 December 13th 06 03:34 PM
WorkSheet Present Dthmtlgod[_3_] Excel Programming 1 December 10th 04 05:40 PM
Checking if worksheet is blank Tommi[_2_] Excel Programming 3 October 31st 03 02:22 PM


All times are GMT +1. The time now is 05:24 PM.

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

About Us

"It's about Microsoft Excel"