简体   繁体   English

使用 max/min 函数记住 Excel 中动态数据的高点/低点

[英]Using max/min functions to remember highs/lows in dynamic data in Excel

I have dynamic data shown in Excel.我在 Excel 中显示了动态数据。 The data itself is pulled using COM from external application, and it is basically number changing over time (for example, outside temperature which is received from weather website).数据本身是使用 COM 从外部应用程序中提取的,它基本上是随时间变化的数字(例如,从天气网站接收的外部温度)。

Is there some convenient way to store MIN/MAX() of value observed during some period without use of VBA and macroses?是否有一些方便的方法可以在使用 VBA 和宏的情况下存储在某个时期观察到的 MIN/MAX() 值? Using simple formula in max_cell like =IF(data_cell>max_cell, data_cell, max_cell) gives circular reference.max_cell使用简单的公式,如=IF(data_cell>max_cell, data_cell, max_cell)给出循环引用。

If you turn Iteration on then the circular reference will work ok on a continuous basis如果您打开迭代,则循环引用将持续正常工作

And rather than an IF you can just use in A1 (where A1 is max_cell, A2 data_cell)而不是 IF 你可以只在 A1 中使用(其中 A1 是 max_cell,A2 data_cell)

=MAX(A1,A2)

Enabling Iteration启用迭代

  • In Excel 2003, From the Tools menu, select Options.在 Excel 2003 中,从工具菜单中,选择选项。 2. In the Calculation tab, select the Iteration checkbox and click OK. 2. 在计算选项卡中,选中迭代复选框并单击确定。
  • Iteration xl2007 迭代xl2007
  • Iteration xl2010 迭代xl2010

I appreciate you asked for a non VBA solution but I will offer one as it is quite trivial to implement and understand.感谢您要求提供非 VBA 解决方案,但我会提供一个,因为实施和理解非常简单。 I'll leave it up to you whether you want to use it or not.不管你想不想用,我都会留给你的。

Suppose your data is organised as follows in Sheet1 of your workbook:假设您的数据在工作簿的Sheet1中组织如下:

    A    B    C
1   Temp Max  Min
2   25   32   14

The following code will update Max and Min whenever Temp changes:每当Temp更改时,以下代码将更新MaxMin

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim temp As Range, max As Range, min As Range

    Set temp = Range("A2") //Change for your specific set-up
    Set max = Range("B2")  //Change for your specific set-up
    Set min = Range("C2")  //Change for your specific set-up

    If Not Intersect(temp, Target) Is Nothing Then
        max = WorksheetFunction.max(Target, max)
        min = WorksheetFunction.min(Target, min)
    End If
End Sub

For clarity, to add this code from worksheet:为清楚起见,从工作表中添加此代码:

  1. Open VB Editor ( ALT + F11 )打开 VB 编辑器 ( ALT + F11 )
  2. In Project Explorer double click Sheet1项目资源管理器中双击Sheet1
  3. Select Worksheet in left hand drop down menu and then Change in right hand drop down在左侧下拉菜单中选择Worksheet ,然后在右侧下拉菜单中选择Change

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM