Formula retaining last value of cell ?

snownut2

New Member
Joined
Sep 22, 2011
Messages
18
I am trying to use an "IF" statement to either apply a formula or retain the last value of the cell, is there a way to accomplish this.

eg. = IF( A1=B1, "retain last value", D1)

last value = the value of the cell prior either to A1 or B1 being changed.


Thanks for any assistance.

Bruce
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
I've tried this;

=IF (A1<>B1, D1)

it returns "FALSE" when A1 & B1 are equal.

Is there a way to leave the Cell as it was if A1 & B1 are equal ?
ie; do nothing in that case.
 
Upvote 0
Hi,

You cannot achieve this with a formula, only with VBA

Maybe this

Right-click on the sheet-tab
View code
and paste the code below in the right-panel

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    If Not Intersect(Target, Range("A1:B1")) Is Nothing Then
        If Range("A1").Value <> Range("B1").Value Then
            Range("C1").Value = Range("D1").Value
        End If
    End If

End Sub

HTH

M.
 
Upvote 0
Marcelo thank you very much your code worked perfectly, however i am really trying to have that apply to every row in the worksheet, not just row 4.

I know that is exactly what I had asked for, as I thought a formula would work I could have just copied it the the rest of the column.


Thanks again

Bruce
 
Upvote 0
Marcelo thank you very much your code worked perfectly, however i am really trying to have that apply to every row in the worksheet, not just row 4.

I know that is exactly what I had asked for, as I thought a formula would work I could have just copied it the the rest of the column.


Thanks again

Bruce

Maybe...

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
 
    If Not Intersect(Target, Range("A:B")) Is Nothing Then
        If Range("A" & Target.Row).Value <> Range("B" & Target.Row).Value Then
            Range("C" & Target.Row).Value = Range("D" & Target.Row).Value
        End If
    End If
 
End Sub

M.
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,879
Members
452,948
Latest member
Dupuhini

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