2012-11-01 40 views

回答

0
  1. 将A1的值存储在A2中。
  2. 执行响应A1中的更改​​的事件。
  3. 当事件被触发时,比较A1和A2,如果A1更小,则存储新值。

这个假设已经有一个在A2的值:

Private Sub Worksheet_Change(ByVal Target As Range) 
    If Target.Address = "$A$1" Then 
     Dim a2val As Variant 
     Dim a1val As Variant 
     a2val = Range("$A$2").Value2 
     a1val = Range("$A$1").Value2 
     If a1val < a2val Then 
      Range("$A$2").Value2 = a1val 
     End If 
    End If 
End Sub 
+0

对不起,你的代码不起作用 –

+0

@RajuKumar你把代码放在正确的Worksheet对象中吗?我不喜欢这样说,但代码适用于我。 –

相关问题