Macro to make one cell copy the value of a cell that changes

spiffmonkey1

New Member
Joined
Jun 23, 2011
Messages
41
Hi,

I want a macro that runs automatically when a certain cell (C6
) changes. When C6 changes, I want D6 to copy the original value of C6 before the change.

Thanks
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Just realized. What do you mean "original value"???
 
Last edited:
Upvote 0
In worksheet module.
Code:
[COLOR=blue]Private[/COLOR] [COLOR=blue]Sub[/COLOR] Worksheet_Change([COLOR=blue]ByVal[/COLOR] Target [COLOR=blue]As[/COLOR] Range)
    [COLOR=blue]If[/COLOR] Target.Address = Range("C6").Address [COLOR=blue]Then[/COLOR]
        Range("D6") = Range("C6")
    [COLOR=blue]End[/COLOR] [COLOR=blue]If[/COLOR]
[COLOR=blue]End[/COLOR] [COLOR=blue]Sub[/COLOR]


Is it possible to make the cell D6 equal to the original value of C6. For example, if C6 = 30,000 and then the value was changed. D6 would then change to 30,000 because C6 had change to a new value

Thanks
 
Upvote 0
Try

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim x As Variant
If Target.Address(False, False) = "C6" Then
    Application.EnableEvents = False
    x = Target.Value
    Application.Undo
    Target.Offset(, 1).Value = Target.Value
    Target.Value = x
    Application.EnableEvents = True
End If
End Sub
 
Upvote 0
Hi that seems to work.
Is it possible for me to target the undo value to another worksheet.
Like if I wanted to target D6 in worksheet 2 instead

Thanks!

When I tested the target to be a certain range or cell like-
Private Sub Worksheet_Change(ByVal Target As Range)
Dim x As Variant
If Target.Address(False, False) = "C6" Then
Application.EnableEvents = False
x = Target.Value
Application.Undo
Target.Cells(7, F).Value = Target.Value
Target.Value = x
Application.EnableEvents = True
End If
End Sub

It changes another cell
I just want to know the reason why so i can understand the macro
 
Upvote 0
Try

Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
Dim x As Variant
If Target.Address(False, False) = "C6" Then
    Application.EnableEvents = False
    x = Target.Value
    Application.Undo
    Sheets("Sheet2").Range("D6").Value = Target.Value
    Target.Value = x
    Application.EnableEvents = True
End If
End Sub
 
Upvote 0
Try

Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
Dim x As Variant
If Target.Address(False, False) = "C6" Then
    Application.EnableEvents = False
    x = Target.Value
    Application.Undo
    Sheets("Sheet2").Range("D6").Value = Target.Value
    Target.Value = x
    Application.EnableEvents = True
End If
End Sub

Awesome thanks so much!
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

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