VBA - before delete

  • Thread starter Thread starter wana be xl master
  • Start date Start date
W

wana be xl master

Hi there,

I'm using Workbook_SheetChange event. How can I capture the cell value
before user press delete button, then through the if statement if the
condition fails I want to put back the same value on the cell.

Appreciate any help.
Thanks,
 
wana be xl master said:
Hi there,

I'm using Workbook_SheetChange event. How can I capture the cell value
before user press delete button, then through the if statement if the
condition fails I want to put back the same value on the cell.

Appreciate any help.
Thanks,

Use Worksheet_SelectionChange.
I've not tested, but I expect that Worksheet_SelectionChange
occurs before the user does ant hanky panky in a selection..
 
Something like:
Dim NewValue as string
Dim OldValue as string
NewValue=Target.Value
Application.EnableEvents=False
Application.Undo
OldValue=Target.Value
'Do your check here
'Note that the old value is in the target cell. Leave it if you wish
or:
Target.Value=NewValue
Application.EnableEvents=True
Otto
 
Thanks Otto & Horward.
As Otto sugested the "undo" works perfectly.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top