PDA

View Full Version : How to capture user last key press using VBA in Excel?



agarwaldvk
01-03-2012, 06:44 PM
Hi Everybody


I have a 'Worksheet_Change()' event. As a part of the code inside the procedure, I want to be able to distinguish if the user has manually changed the value in a cell (manual entry) or has changed the value of the cell by copying/pasting data in that cell.

To that end, I am trying to capture if the last key press before the code in the 'Worksheet_Change()' is executed. Is there a way to capture what was the last key pressed before the code in the 'Worksheet_Change()' ran?

I looked at the 'GetAynckeyState()' API function but that won't do the job since it will only track the state of the key at the INSTANT the function was called - which doesn't help in this case.


Any othe suggestion?



Best regards


Deepak

Jan Karel Pieterse
01-04-2012, 04:09 AM
I don't think you can get that information. What I'd suggest is a different approach: re-direct the paste command to a VBA procedure and act accordingly there.