Rick excuse me for not getting back to this sooner.
I did some tests and found out where the error takes place - but I don't
know why or how to correct it. Here's the deal.
1. I tried your solution and it didn't work. It only works, as mine does,
if
I enter the desired value in the cell manually and press enter.
2. I closed the spreadsheet and tried only the proposed solution in a
brand
new spreadsheet. This works flawlessly.
3. Having the new file open, I re-opened my original spreadsheet and both
the original as the new file exhibit the same behaviour. Formatting
doesn't
take place not even in the new file.
Therefore my original spreadsheet "does" something to the environment that
affects every open spreadsheet.
After working with the debugger I found the following to take place, which
I
hope you can figure out.
[I put a break in the first line after the "If .column =3 then" so that I
can watch what happens.]
The "If .Value = True then" works for both TRUE and FALSE values.
** BUT **
As soon as I hit F8 in the ".Offset(0, -2).Resize(1,
2).Interior.ColorIndex
= xlNone" statement
(A) The yellow execution line pointer disappears
(B) The locals window in the debugger blanks out
(C) The execution obviously halts and control returns to the spreadsheet
Yet, if I manually press F2 and ENTER in the same cell as I was before and
Worksheet_Change execution halted, I get the same break in the debugger,
execution continues after the afore mentioned F8, interior coloring is
performed and the event runs past the EndIfs and closes normally.
I am aware that you cannot reproduce this behaviour.
Can you imagine what could stop the execution of the routine if it is
initiated by an InCell Data Validation DropDown Selection "path" whereas
nothing goes wrong after a direct (manual) value entry?
Is there a way to get some information from the debugger as to what goes
on
when I hit F8 and command execution stops? Mind you that the actual
command
is not executed. Termination takes place BEFORE execution - that's why the
cells don't become grey.
Thanks a lot in advance for any effort you make. I am at the end of my
rope
with this one.
Rick Rothstein said:
Actually, I get your code to work properly in a Change event procedure;
however, the clearing of the interior color isn't done correctly using
the
Color property. See if this code works (make sure you are putting it into
the correct Worksheet's code window)...
Private Sub Worksheet_Change(ByVal Target As Range)
With ActiveCell
If .Column = 3 Then
If .Value = True Then
.Offset(0, -2).Resize(1, 2).Interior.ColorIndex = xlNone
Else
.Offset(0, -2).Resize(1, 2).Interior.Color = RGB(128, 128, 128)
End If
End If
End With
End Sub
--
Rick (MVP - Excel)
Bernie thanks for your answer but it's not the Enable Events thing. I
tried
it, it wasn't disabled anyway, but nothing changed.
Here's what I have that is not working (I am checking if i am in a
Column
C
cell and it has been changed - then I shade or clear the two cells to
the
left - Columns A & B). I am afraid that the ActiveCell approach creates
problems.
prow = ActiveCell.Row
pcol = ActiveCell.Column
If pcol = 3 Then
If ActiveCell.Value = True Then
ActiveCell.Offset(0, -1).Interior.Color
=
xlNone
If ActiveCell.Value = True Then
ActiveCell.Offset(0, -2).Interior.Color
=
xlNone
If ActiveCell.Value = False Then
ActiveCell.Offset(0, -1).Interior.Color
= RGB(128, 128, 128)
If ActiveCell.Value = False Then
ActiveCell.Offset(0, -2).Interior.Color
= RGB(128, 128, 128)
End If
:
Doctor G,
The change event is triggered by choosing a value from the Data
Validation dropdown.
Make sure that you haven't disabled events accidentally:
Sub ResetEvents()
Application.EnableEvents = True
End Sub
--
HTH,
Bernie
MS Excel MVP
I set up a Worksheet_Change event so as to change the background
color
of a
row relevant to the value of the column C cell (True/False). It
works
after
manually changing the values in Column C.
Following ND Pard's advice I managed to set up Data Validation in
the C
Column cells so as to restrict entry to True/False. This works.
The problem is that InCell DropDown Validation does not seem to
trigger
the
Worksheet_Change event and the row background color does not reflect
the
value change anymore.
Is this standard behaviour or am I doing something wrong? If it is
standard,
where should I code the background change mechanism so that it
works?