Record previous cell value

Retroshift

Board Regular
Joined
Sep 20, 2016
Messages
119
Office Version
  1. 2019
Platform
  1. Windows
Hello,

I am looking for VBA code which copies the old cell text value of cell A1 (the value of A1 is returned by a formula which references to other cells) to cell A2, every time cell A1 contains a new and updated value.
(The value of cell A2 should also remain unchanged whenever cell A1 is selected.) I have been looking online but cannot find the right script. Thanks
 
I found a script that logs cell values into a column C before refreshing. I want to remove all the refreshed duplicates in this column but the script below seems to get stuck in an infinite loop.
How could the "remove duplicate rows in column C" code be rewritten to prevent it from looping?

VBA Code:
Private Sub Worksheet_Calculate()
Application.EnableEvents = False
Me.Range("C" & Me.Rows.Count).End(xlUp).Offset(1).Value = Me.Range("A5").Value
Application.EnableEvents = True

Range("C1:D1").RemoveDuplicates Columns:=1
End Sub
 
Upvote 0

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
So, what will cause this to happen.

If the script runs when a formula causes a cell value to change how could it be possible for the script to record what was in the cell prior to the cell value changing.

If you have a formula like the one, you're showing here that will work maybe try that.
 
Upvote 0
Cross-posted without links again.

Please supply links to all sites where you have asked this question.
 
Upvote 0
So, what will cause this to happen.

If the script runs when a formula causes a cell value to change how could it be possible for the script to record what was in the cell prior to the cell value changing.

If you have a formula like the one, you're showing here that will work maybe try that.
The worksheet B script runs and copies a cell value (generated by a formula and updated by a macro button) from worksheet A into a column C in worksheet B.
The thing is that the script copies the cell value every time the workbook is being refreshed, so there are a lot of duplicate value copies in column C.

Do you know what code I have to add to the Worksheet_Calculate sub, to regularly run and remove the duplicate values in column C? Without duplicate removals, the column would have hundreds of values in a single day already, and the workbook would get heavy.

My VBA knowledge is very basic.
 
Upvote 0
The worksheet B script runs and copies a cell value (generated by a formula and updated by a macro button) from worksheet A into a column C in worksheet B.
The thing is that the script copies the cell value every time the workbook is being refreshed, so there are a lot of duplicate value copies in column C.

Do you know what code I have to add to the Worksheet_Calculate sub, to regularly run and remove the duplicate values in column C? Without duplicate removals, the column would have hundreds of values in a single day already, and the workbook would get heavy.

My VBA knowledge is very basic.
This is beyond my knowledgebase.
I will continue to monitor this thread to see what I can learn.
 
Upvote 0

Forum statistics

Threads
1,223,702
Messages
6,173,932
Members
452,539
Latest member
delvey

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