vba - Excel. Worksheet Change to Worksheet Calculate -
i have code runs on "worksheet_change" event.
the value in cell "a1" changes live feed.
i need adapt code event work "worksheet_calculate" event.
every time cell value a1 changes, automatically old value must shown in a2.
a1 new value a2 old value
here code:
private sub worksheet_change(byval target range) dim newvalue, oldvalue if target.address <> "$a$1" exit sub application.enableevents = false target newvalue = .value application.undo oldvalue = .value .value = newvalue end range("a2").value = oldvalue application.enableevents = true end sub
for 1 sheet place code in sheet module (initial old value empty)
option explicit private oldval string private sub worksheet_calculate() updateoldvalue me.range("a1") end sub private sub worksheet_change(byval target range) updateoldvalue target end sub '------------------------------------------------------------------------------------------ public sub updateoldvalue(byval target range) target if .countlarge = 1 if .address = "$a$1" .offset(1, 0) = oldval oldval = .value2 end if end if end end sub
.
for multiple sheets, place code in new vba module, , call same way:
updateoldvalue me.range("a1")
or updateoldvalue target
:
option explicit private oldval string public sub updateoldvalue(byval target range) target if .countlarge = 1 if .address = "$a$1" .offset(1, 0) = oldval oldval = .value2 end if end if end end sub
Comments
Post a Comment