benmc...@gmail.com
unread,May 31, 2013, 7:45:35 AM5/31/13You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
Scott,
There are 2 ways that I came up with to address this need. First, you could use a macro on the worksheet's Change event. I have copied code to accomplish this below.
The other way might be easier, though. You could use a combination of data validation and conditional formatting to achieve the same effect. To do so, try the following:
1. Select column A
2. Open the Data Validation dialog box and choose "Custom"
3. For the formula enter: =IF($K$1=3, OR(A1<80000, A1>86666)=FALSE, TRUE)
4. Complete any other info you wish in the data validation dialog (i.e. input message, error alert etc.)
5. Next, go to the conditional formatting settings and use the formula option.
6. For the formula enter: =AND($K$1=3, OR(A1<80000, A1>86666), A1<>"")
7. Select appropriate formatting to highlight invalid data.
The effect of the data validation and conditional formatting is that if K1 = 3, users will be alerted whenever invalid data is entered into column A. In the case that invalid data already exists in column A and K1 is later changed to 3, all invalid data will be highlighted.
If you would prefer the macro route, try this one:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 Or Target.Address = "$K$1" Then
If Range("K1") = 3 Then
If WorksheetFunction.Min(Range("A:A")) < 80000 Or WorksheetFunction.Max(Range("A:A")) > 86666 Then
MsgBox "Values in column A must be between 80000 and 86666!", vbExclamation + vbOKOnly, _
"Invalid Data"
End If
End If
End If
End Sub