Previous cell value

bhsoundman

New Member
Joined
Jul 17, 2010
Messages
32
Office Version
  1. 365
Platform
  1. MacOS
Hi All,

I'm looking to return the value of of the last entry in a range. I've attached the sample here
My data range is C5:I15, and my return range is D2

Basically when I enter data into my data range, I want that data to appear in D2. So, D2 is always the value of the previous cell. Seems simple, but I keep running into issues.

Thanks!!
 

Attachments

  • Screen Shot 2022-03-30 at 8.04.10 AM.png
    Screen Shot 2022-03-30 at 8.04.10 AM.png
    247.8 KB · Views: 17

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
The correct answer depends on the data type and the order in which the range is filled. Assuming numeric data filled across then down, this formula will work.
Excel Formula:
=LOOKUP(1E+100,INDEX($C$5:$I$15,MATCH(1E+100,$C$5:$C$15),0))
 
Upvote 0
The correct answer depends on the data type and the order in which the range is filled. Assuming numeric data filled across then down, this formula will work.
Excel Formula:
=LOOKUP(1E+100,INDEX($C$5:$I$15,MATCH(1E+100,$C$5:$C$15),0))
Thanks for the formula. I may need to clarify that the data will be text & the answer that would return in D2 would be the text regardless of where it appears in the data range. Whatever is the most recent entry is what should be returned into D2.

Thanks!!
 
Upvote 0
In that case you will need to use vba, a formula will not be able to track the order in which entries are made if there is no pattern to the entry.

Copy the code below and paste it into the relevant worksheet module by right clicking the sheet / tab name in excel and selecting 'View Code' from the context menu.
Close the code editor and save the workbook, if you see a pop up when you try to save then you will need to follow the instructions to save as macro enabled.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("C5:I15")) Is Nothing Then
    If Target.CountLarge = 1 Then
        If Target.Value <> "" Then Range("D2").Value = Target.Value
    End If
End If
End Sub
Hope this helps.
 
Upvote 0
Solution
In that case you will need to use vba, a formula will not be able to track the order in which entries are made if there is no pattern to the entry.

Copy the code below and paste it into the relevant worksheet module by right clicking the sheet / tab name in excel and selecting 'View Code' from the context menu.
Close the code editor and save the workbook, if you see a pop up when you try to save then you will need to follow the instructions to save as macro enabled.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("C5:I15")) Is Nothing Then
    If Target.CountLarge = 1 Then
        If Target.Value <> "" Then Range("D2").Value = Target.Value
    End If
End If
End Sub
Hope this helps.
YOU RULE! This works exactly as needed! Thanks so much.
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,318
Members
452,634
Latest member
cpostell

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