VBA code to affect value of a named range
Do you know if the _Change event is occuring? I just went through an
exercise in Excel 2003 and found that the _Change event doesn't even fire if
the change is made in a merged cell group.
Also, I don't know how much there is to be done on this particular sheet,
but if there's much on it to be done by the user, and you do get the code
working on a Change event, they're going to see that prompt quite a bit as
long as the value remains False.
Also, once they've responded Yes to the MsgBox prompt, they'll never see the
question again - the .value will change to true and remain that way. Might
be a better place to put it, such as the workbook's _Save or _Close events?
You can check to see if the Change event is firing and calling the code by
putting breakpoints in the code, or placing a STOP statement within that code
segment - could put one within the first IF...Then block, and another just
before the End Sub statement just for testing.
"Dave O" wrote:
I wrote code intended to evaluate and reassign the value of a named
range based on an "on change" worksheet event. The code changes the
named range value when run as a separate routine in a module, but
doesn't run from the worksheet trigger. Can anyone correct this code,
or tell me what I've done wrong? Thanks. Code follows:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Response As String
If Evaluate(Names("DatesUpdated").Value) = False Then
Application.Undo
Response = MsgBox("Have you updated the dates?", vbYesNo)
If Response = vbYes Then
Names("DatesUpdated").Value = True
End If
End If
End Sub
|