Mimic Value Being Typed Into Cell

  • Thread starter Thread starter Matthew Wieder
  • Start date Start date
M

Matthew Wieder

via VBA, I need to mimic someone writing a value into a cell. Just
changing the value via Range.Value doesn't fire the event I need, so I
need it to behave the same way it does one someone manually enters the
value. Does anyone know how to do this from code?
thanks!
 
Matthew,

Since it's to simple to be overseen I'm not sure whether this will help, but
it does somehow run an "event procedure" (in this case EventSub) after
"entering" (via VB) a value in a cell. Just follow entering the line in
which you give the cell a value with a call to the "event procedure" you
want after running the cell, and do that

Sub TryIt()
ActiveCell.Value = 25
Call EventSub
End Sub
Private Sub EventSub()
MsgBox "Fake Event fired"
End Sub

--
Regards,
Auk Ales

* Please reply to this newsgroup only *
* I will not react on unsolicited e-mails *
 
What event do you claim isn't being fired. Perhaps you have disabled
events, because the change event fires if the cell value is changed either
manually or by code. If you are using selection change, then you can have
your code select the cell if you need to fire the event.
 
It's the OnEntry handler that has been setup by an add-in. Just
changing the cell value doesn't trigger the event, but I think a
combination of setting the activecell and calling the handler with Call
should do the trick...
thanks!
 
Onentry only fires when the cell is edited manually.

No, setting the activecell and calling the handler won't work unless you
mean selecting the cell and having the change event call the handler.
However, this would fire before the cell is edited which is probably not
what you want.

If you are having code modify the cell, then have it call the handler as
well.
 
I'm not sure I understand your response - you say that "No, setting the
activecell and calling the handler won't work" but then you say the
solution is "have it call the handler as well."
In your understanding, can I call the OnEntry handler or not from my
code automating the cell value change?
thanks,
-Matt
 
That is why we have paragraphs.

the SelectionChange event can call the macro you assigned to onentry, but it
would call it before the cell value has been changed.

The code that changes the value in the cell could call the macro assigned to
your onentry event.

Two different thoughts. The "It" in the second sentence you cite was
referring to the subject of the first clause in the same sentence, not the
first sentence in the preceding paragraph.

If the selectionchange event is the macro which modifies the cell, then you
will have to sort that out, but it doesn't change the answer.
 
and therein lies the clarification - we hadn't been discussing the
selectionchange event so I didn't understand that was your point of
reference. In any event, I think we're on the same page now, so thanks
for yoru help.
 
Hi Matthew,

Thanks for your quickly reply!

Thanks for posting in the community.

First of all, I would like to confirm my understanding of your issue.

From your description, I understand that you hope when the change the
value in the cell, a event will be fired.
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.


I agree with TOM's suggestion.
Here is my test code.

Sub Test()
'run the macro first to set the OnEntry
ThisWorkbook.ActiveSheet.OnEntry = "Hello"
End Sub
Sub Hello()
MsgBox "hello"
End Sub
Sub sdaf()
'This will not fire the Hello() Macro
Application.ActiveSheet.Cells(1, 1) = "fdsf"
End Sub

Also have you tried to hook the SheetChange event, which will be fired when
the cell was changed by manual or by coding.

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
MsgBox "Sheet changed"
End Sub


Please apply my suggestion above and let me know if it helps resolve your
problem.


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Matthew,

Thanks for posting in the community.

Did my suggestion help you?
If you still have any question on this issue,please feel free to let me
know.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top