Conditional locking of a cell

G

GordL

Does someone know a way to prevent a user from entering data into a cell
unless there is something first entered into different cell. Here is an
example of what I am trying to do.

=IF(A1="",disable data entry in D1,enable data entry in D1)
=IF(A1="",D1="")

The application is a time sheet. I want to prevent a person from entering
their hours until a billing code is first entered. In addition, if the
billing code is deleted then I want to delete the hours booked against it as
well.

Thanks for any tips

Best regards
GordL
 
L

Luke M

right click on sheet tab, view code, paste this in:

Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("A1")) Is Nothing And _
Intersect(Target, Range("D1")) Is Nothing Then Exit Sub

If Range("A1").Value = "" Then
Application.EnableEvents = False
Range("D1").Value = ""
'Include a message, if desired
MsgBox "A1 must have a value", vbOKOnly
Application.EnableEvents = True
End If

End Sub


'Note that users can still input data into D1, but it is immediately deleted.
'While it might be possible to prevent this via some formula in data
validation
'you needed to use VB anyway to clear D1, so I combined the two features
 
J

Jim Thomlinson

I would be inclined to use a custom data validation for that. In Cell D1 select
Data ->Validation -> Custom | =A1 <> ""
and uncheck Ignore Blanks.
Change the error message to something that indactes they need to enter a code
Choose Ok.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top