LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Multiple If Statement

I want to write a sub to do the following when a user closes the worksheet:

1) Using a message box, check if data has been entered into cell named
"Date". If the user answers yes, save the file. If the user answers no,
goto the "Date" cell.
2) Using a message box, check if data has been entered into cell named
"Shift". If the user answers yes, save the file. If the user answers no,
goto the "Shift" cell.

The code just check for the "Date" Cell but not for the "Shift" Cell.
Actually, there are 8 other cells in my worksheet that I want to check.
Please 1) check my code below, and 2) offer any suggestions on how to write a
better code.

Private Sub Workbook_BeforeClose(Cancel As Boolean)

Dim ans As Variant

If Worksheets("01-01-07").Range("Date").Value = " " Then
Dans = MsgBox("Have a date been entered? If not, please enter a
date.", vbYesNo)
If Dans = vbNo Then
Application.Goto Worksheets("01-01-07").Range("Date")
Cancel = True
ElseIf Worksheets("01-01-07").Range("Shift").Value = " " Then
Sans = MsgBox("Have a work shift been entered? If not, please enter
a work shift.", vbYesNo)
If Sans = vbNo Then
Application.Goto Worksheets("01-01-07").Range("Shift")
Cancel = True
Else
Application.DisplayAlerts = False
ThisWorkbook.Save
ThisWorkbook.Close
Application.DisplayAlerts = True
End If
End If
End If
End Sub


--
Thanks!
 
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
Multiple IF statement J.Scargill[_2_] Excel Worksheet Functions 1 April 8th 10 04:28 PM
I think I need a multiple IF statement, or is there another way? Carl Waring Excel Worksheet Functions 5 March 18th 10 10:57 AM
multiple if statement blake7 Excel Discussion (Misc queries) 6 February 10th 09 08:44 PM
If statement with multiple criteria and multiple results Tickfarmer Excel Discussion (Misc queries) 3 January 28th 09 08:11 PM
Multiple If Statement TamIam Excel Worksheet Functions 8 October 18th 06 08:55 PM


All times are GMT +1. The time now is 05:35 AM.

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"