View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
JLGWhiz[_2_] JLGWhiz[_2_] is offline
external usenet poster
 
Posts: 1,565
Default Stop users leaving cells blank

Put the code in the worksheet code module for the sheet where you want it to
run.

Private Sub Worksheet_Change(By Val Target As Range)
If Target.Column = 1 Then
For Each c In Range("A1:A4")
If IsEmpty(c.Value) Then
MsgBox "You must fill in cell " & c.Address
Application.Goto c
Cancel = True
Exit For
End If
Next cell
End If
End Sub






"Lozzaw" wrote in message
...
Hi

I have found some code from another thread which stops users leaving cells
blank and displays a warning message when the user attempts to save the
file:

Dim cell As Range
For Each cell In Sheets("Sheet2").Range("A1,A2,A3,A4")
If IsEmpty(cell.Value) Then
MsgBox "You must fill in cell " & cell.Address
Application.Goto cell
Cancel = True
Exit For
End If
Next cell

Now, this works fine in the file itself and when I save it as a .xlsm file
(I am using Excel 2007). However, the problem is that when you go to open
the
file the macro is intially disabled, as explained by the Information Bar.
For
the macro to work, it has to be activated by the user. So, if a user
choose
not to activate the code, then they can just leave the cells blank. Is
there
a way round this to force the macro to work?

Thanks