PDA

View Full Version : Conditional Formating



nedy_03
02-26-2007, 04:55 AM
Hello,

I'm facing this problem: an the and of a row I have a combo box with 2 options : yes and no. If I choose "yes" I would need the whole row to be filled with the green color! ... Could u please help me on this? ..

Tnx,
Nedy

Simon Lloyd
02-26-2007, 05:12 AM
Drop this into the combobox change event:

If Me.Value = "Yes" Then
ActiveCell.EntireRow.Select
With Selection.Interior
.ColorIndex = 4
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
End If
it should do the trick for you!

Regards,
SImon

For a full explanation on Conditionla Formatting check here: http://www.xldynamic.com/source/xld.CF.html

Charlize
02-26-2007, 05:18 AM
Private Sub Worksheet_Change(ByVal Target As Range)
'Column E and value is Yes
If Target.Column = 5 And Target.Value = "Yes" Then
ActiveSheet.Range("A" & Target.Row, "E" & Target.Row).Interior.Color = vbGreen
End If
End Sub

nedy_03
02-26-2007, 05:32 AM
To be more precise I have a validation list with the two options ... not a combo box button as I said before :banghead: ...

I've assigned the code u wrote for me to a check box button, but I get an error on the "Me." at the begining of the code. On the checkBox the code I've put is this :

Sub CheckBox7_change()
If Value = "Yes" Then
ActiveCell.EntireRow.Select
With Selection.Interior
.ColorIndex = 4
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
End If
End Sub

Simon Lloyd
02-26-2007, 05:39 AM
Thats because "ME" refers to the object which would have been the combobox, you need to say If WHAT value so which ever cell is validated like F1 then you say If Range("F1").Value="Yes" ThenRegards,
SImon

P.S if you do not specify a worksheet the code will run on the activesheet! Also Rather than Activecell.EntireRow you may have to specify the row like: Range("1,6").EntireRow.Selectin ("1,6") 1 = row 1 and 6= column 6

Norie
02-26-2007, 06:35 AM
Why do you even need code?

Can't you just use conditional fomatting as suggested by your thread title?

Simon

Me doesn't refer to the control.:)

Simon Lloyd
02-26-2007, 06:56 AM
Norie please excuse my ignorance, but i thought the use of "ME" in the objects code sheet referred to the object like "Unload Me" in a UserForm, therefor i thought within the CombBox_Change you could use ME?

Regards,
SImon

Norie
02-26-2007, 07:02 AM
Simon

I don't quite know the full technical explanation but Me refers to the 'container' and object is in.

Hence when used in a userform module it refers to the userform.

And when used in a worksheet module it refers to that worksheet.

It can't be used to refer to an actual control as far as I know.

Bob Phillips
02-26-2007, 07:03 AM
Norie please excuse my ignorance, but i thought the use of "ME" in the objects code sheet referred to the object like "Unload Me" in a UserForm, therefor i thought within the CombBox_Change you could use ME?


It refers to the containing object Simon, such as the form or the worksheet that a child objcet is within.

Bob Phillips
02-26-2007, 07:04 AM
Just use conditional formatting with an absolute column

=$M2="Y"

no need for code at all.

Charlize
02-26-2007, 07:05 AM
Try the worksheet change code. When using your validation pulldownmenu (in column E), the line will color green with a Yes chosen from your list.

Charlize

Simon Lloyd
02-26-2007, 07:11 AM
Thanks for the Explanation - i didn't test the code - but there again it is something i would have done!, so i've got it now referrering to anything other than the host object has to be referred to by its own name.

Regards,
Simon

nedy_03
02-27-2007, 01:05 AM
I didn't manage with the code :banghead: ... I've attached the file ... I would need that code or conditional formating in "Suppliers!M3" ... When I choose "Yes" the whole row or just the cells in front of M3 should get one specific color! .. could someone help me on this pls ...

Bob Phillips
02-27-2007, 02:26 AM
.

nedy_03
02-27-2007, 05:13 AM
Thx ...