View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Biff
 
Posts: n/a
Default Can I make certain cells required?

Goto the VBE, Open the Immediate window, type this line then hit ENTER

Application.EnableEvents=FALSE

Exit the VBE

Save your file

Go back into the VBE, open the Immediate window, type this line then hit
ENTER:

Application.EnableEvents=TRUE

Biff

"~C" wrote in message
...
Paul,

This puts me in a Catch 22, as I am then not able to save it myself! What
to do?

~C

"Paul B" wrote:

~C, here is one way, put in this workbook code

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
'user must enter data into all the defined cells before save
Dim test_rng As Range
Dim ret_str As String
Dim cell As Range
Set test_rng = ActiveSheet.Range("A1:A2,H4") '**change range here****
For Each cell In test_rng
If cell.Value = "" Then
If ret_str = "" Then
ret_str = cell.Address
Else
ret_str = ret_str & " and " & cell.Address
End If
End If
Next
If ret_str < "" Then
MsgBox "There is information missing in cell(s): " & ret_str &
Chr(10) _
& Chr(10) & "You must fill in the cell(s) before you can save" _
, , "Missing Information"
Cancel = True
Else
End If
End Sub

--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2002 & 2003

"~C" wrote in message
...
I am creating a form and certain fields are required. Can I force the
user
to input some value before they can save?

Thanks!

~C