VBA Excelsearch栏最后更改的值

我有一个专栏: 这个列的值从U10U500

我需要得到的是列的最后一个变化的值,如果它不改变,那么一个文本“假”或什么,如果最后一个变化的值是一个空单元格,然后忽略..

 Column U 11 11 5 11 11 21 

例如这里的结果应该是21。

我试过比较两行和条件格式,但是这样一个大范围做这一切的每一行是有点太多了。

有没有人知道这样做的好方法?

像这样的事情应该这样做…

 Sub test() Dim LastRow As Long, i As Long With Worksheets("Sheet1") 'your sheet name LastRow = .Cells(.Rows.Count, "U").End(xlUp).Row 'find last used row in column U For i = LastRow To 2 Step -1 'loop from last row to row 2 backwards (row 1 can not be compared with row before) If .Cells(i, "U").Value <> .Cells(i - 1, "U").Value Then 'compare row i with row before. If it changes then ... MsgBox "Last row is: " & .Cells(i, "U").Address & vbCrLf & _ "Value is: " & .Cells(i, "U").Value Exit For 'stop if last changing row is found End If Next i End With End Sub 

它从列U中最后使用的行循环到第一行,并检查当前行是否与以前行不同。 如果是这样就停止。

我不确定你想要的输出。

 IF(AND(RC[-1]<>R[-1]C[-1],ROW(RC[-1])>500,R[-1]C[-1]<>""),RC[-1],"") 

在单元格V10:V500中尝试这个公式

试试这个macros。 首先运行AnalyseBefore子,当你想检查值是否已经改变时,运行AfterAnalyse子。 如果您希望范围是dynamic的,请使用我已经评论的代码,并在范围计算中包含iCount

 Sub AnalyseBefore() Dim iCount Range("U10").Select iOvalue = Range("U500").Value 'iCount = Selection.Rows.Count Range("Z1").Value = iOvalue End Sub Sub AnalyseAfter() Dim iCount Range("U10").Select iNValue = Range("U500").Value Range("Z2").Value = iNValue iOvalue = Range("Z1").Value If (iOvalue = iNValue) Then Range("U500").Value = "FALSE" End If End Sub