在更改之前检测单元格中的值 [英] Detecting what value was in a cell prior to a change

查看:29
本文介绍了在更改之前检测单元格中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法检测单元格在更改之前要包含的内容.我正在尝试根据单元格中先前的值执行操作.我知道有 Worksheet_Change 但它使用的目标是新值.

Is there a way to detect what a cell use to contain before it was changed. I'm trying to perform actions based on what the previous value was in a cell. I know there's Worksheet_Change but the Target it uses is the new value.

推荐答案

您可以撤消更改,将撤消的值填充到变量中,然后像这样重做更改:

You can undo the change, populate the undone value to a variable then redo the change like so:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim OldValue As Variant, NewValue As Variant
NewValue = Target.Value
Application.EnableEvents = False
Application.Undo
OldValue = Target.Value
Target.Value = NewValue
Application.EnableEvents = True
MsgBox OldValue
End Sub

这篇关于在更改之前检测单元格中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆