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: 50
Default Check for Required Fields, an hilarious error!

This is the first time I have ever been stumped, was desperate, and laughed
until I had tears in my eyes!

I'm using Excel 2003. In the spreadsheet, there are 10 cells, and the
user must select 1 or more options by entering an X in the desired cell(s).
If they SAVE the spreadsheet, at least one of the 10 cells must have data.

I'm thinking, no problem, that's simple. I'm fairly new to Excel VBA, and
coded the following. It works, but it won't let ME save my code without
having an X in at least one of the 10 cells!

Is there a way to save the code only?

Your help would be GREATLY appreciated!

For brevity sake, I only listed conditions for 2 of the cells.

=======
Private Sub Workbook_BeforeSave(ByVal CheckCells As Boolean, Cancel As
Boolean)

Dim TheCells As Range
Dim SomethingWasChecked As String

If CheckCells = False Then

SomethingWasChecked = "N"

If Me.Worksheets("sheet1").Range("A19").Value < "" Then
SomethingWasChecked = "Y"
GoTo StopChecking
End If

If Me.Worksheets("sheet1").Range("A25").Value < "" Then
SomethingWasChecked = "Y"
GoTo StopChecking
End If


StopChecking:

If SomethingWasChecked < "Y" Then
Cancel = True
MsgBox "Please checkmark at least one option or close file without
saving!", vbCritical, "Missing Data!"
End If

End If

End Sub


 
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 have fields to be required Mandatory fields in Excel Excel Worksheet Functions 1 June 6th 08 10:41 PM
WorkbookBeforeSave Event - check required fields before saving LRay67 Excel Programming 3 March 25th 08 05:38 PM
My first post and 11 Hilarious videos mikeyboy82 Excel Discussion (Misc queries) 0 January 10th 06 07:33 PM
Required fields Brian Boguhn Excel Programming 5 January 10th 06 05:51 PM
Required fields Lupe[_2_] Excel Programming 1 June 2nd 04 02:50 PM


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