PDA

View Full Version : Solved: Hi-Lite a cell based on value in another cell



oliver
08-14-2008, 09:26 AM
I have a data validation list box in A1. When a name is selected from the drop down I would like for cell A2 to Hi-Lite indicating to the user a number input is required. When a number is entered in A2 I would like for the Hi-Lite to turn off. Can this be done with Conditional Formatting? Example formulas?
Thanks
Oliver

Bob Phillips
08-14-2008, 10:01 AM
Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "A1:A2" '<== change to suit

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target

If .Address = "$A$1" Then

.Offset(1, 0).Select
Else

If IsNumeric(.Value) Then

.Offset(-1, 0).Select
End If
End If
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub


This is worksheet event code, which means that it needs to be
placed in the appropriate worksheet code module, not a standard
code module. To do this, right-click on the sheet tab, select
the View Code option from the menu, and paste the code in.

RonMcK
08-14-2008, 10:01 AM
Yes.
First create for Data > Validation for column 1
then ...
Highlight column 2 for all applicable rows (I highlighted col 1 and 2, for emphasis)

Open Format > Conditional formatting ...
Change condition 1 to 'Formula is"
Insert formula: '=($A2<>"",$b2="")'
Click Format... button
Select Patterns tab and click on a color
Click OK
Click OK

Test it:
Pick a value for A2
Enter a value in B2


HTH,

RonMcK
08-14-2008, 12:47 PM
Here's a workbook.

Cheers,

oliver
08-15-2008, 05:22 AM
Thanks Ron, your formula works for me. Oliver