VBA code that will return a cells previous value, if that cell has its value deleted but a new value is not inputed

addman24

New Member
Joined
May 13, 2024
Messages
1
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi, looking for vba/macro code that will return an old value to a cell if the user deletes that cells value and doesn't enter anything in. So for example if cell A1 has the value $1000.00, and the user clicks on cell A1 and hits delete so that A1 is blank, and user doesnt enter anything into A1 and then proceeds to select another cell like C1 for example. This macro/vba will restore the value of A1 to $1000.00

Tried doing searches but couldn't find anything.
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
welcome to the forum,
try putting this code in the worksheet code:
VBA Code:
Public lasttime As Variant

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Value = "" And lasttime <> "" Then
Application.EnableEvents = False
Target.Value = lasttime
Application.EnableEvents = True
End If
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
lasttime = Target.Value
End Sub
 
Upvote 1

Forum statistics

Threads
1,216,990
Messages
6,133,895
Members
449,845
Latest member
Lakem

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top