Reputation: 11857
When using an onchange event on some worksheet, I wish to change the Target cell's value inside the onchange script.
I haven't found a way to do this. I've tried:
Target = "some value"
Range(Target.Address) = "some value"
Target.Value = "some value"
But to no avail.
I'm aware that this may trigger again the onchange event, but the script is prepared for that. And in case it is not supposed to be triggered, I may use
Application.EnableEvents = False
before any update and
Application.EnableEvents = True
when done...
Any ideas?
Upvotes: 0
Views: 3086
Reputation: 2718
I know this isn't much of an answer but I need to be able to post code.
The following works absolutely fine for me when entered in the worksheet code section:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
Target.Value = "some value"
Application.EnableEvents = True
End Sub
I select a cell, type "a" and press enter; it's replaced with the text "some value". If you want cell contents to be replaced as you type, you're out of luck; as far as I know the event will only fire after the cell content change.
Upvotes: 3