# Mandatory cells in Excel spreadsheet.



## RevolutionistT (Oct 23, 2008)

At my job we have a spreadsheet that vendors fill out. There are particular fields that we want to be mandatory to fill in before the sheet is returned to us. From what Ive found on the internet there needs to be a VB script put in for this to be accomplished. But how do I figure out which one to use for my worksheet?


----------



## Glaswegian (Sep 16, 2005)

Hi

Yes you would need VBA to do this. Here's a small example using XL2002.

This example uses cell E5 as the mandatory cell. To use this code, open a worksheet, right click on the tab and select 'View Code' - copy and paste the code.

```
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address <> "$E$5" Then Exit Sub

If Target.Value = "" Then
MsgBox "Input required!", vbInformation + vbOKOnly, "Warning"
Target.Activate
End If
End Sub
```
You now cannot enter E5 and leave it blank - it must have a value, even zero.

To ensure that users can only input to specific cells, I usually unlock these cells then protect the sheet. Users can then simply tab to each input cell.


----------

