简体   繁体   English

如何在 Excel 中查找动态单元格的最大值和最小值

[英]How to find max and min of a dyanamic cell in Excel

I wish to have 3 cells in excel.我希望在excel中有3个单元格。

One is dynamic and max and min cell.一种是动态和最大和最小单元格。

So whenever the dynamic value goes to max, the max cell should be updated, else the max value should hold the previous highest value.因此,每当动态值达到最大值时,应更新最大单元格,否则最大值应保持先前的最大值。

Similarly for min as well.对于 min 也是如此。

VBA = Visual Basic for Applications. VBA = 适用于应用程序的 Visual Basic。 To access it, open Excel and press Alt + F11 .要访问它,请打开 Excel 并按Alt + F11 In the Visual Basic Editor (VBE), double click on the sheet name that will have the dynamic cell.在 Visual Basic 编辑器 (VBE) 中,双击将具有动态单元格的工作表名称。 In this example, it is just Sheet1.在此示例中,它只是 Sheet1。 After double-clicking on that sheet name, a code window will open on the right hand side.双击该工作表名称后,将在右侧打开一个代码窗口。 At the top of the code window, use the two drop downs select Worksheet (in order to tell it you want a worksheet event) and then Change (to tell it you want the Worksheet_Change event. It will auto create a line with Private Sub Worksheet_Change(ByVal Target as Range) and will look something like this:在代码窗口的顶部,使用两个下拉菜单选择 Worksheet(为了告诉它您想要一个工作表事件)然后是 Change(告诉它您想要 Worksheet_Change 事件。它将自动创建一个带有Private Sub Worksheet_Change(ByVal Target as Range)的行Private Sub Worksheet_Change(ByVal Target as Range) ,看起来像这样:

在此处输入图像描述

Then just copy this code and paste it in between the Private Sub... and End Sub lines so that it matches the picture:然后只需复制此代码并将其粘贴到Private Sub...End Sub行之间,使其与图片匹配:

Dim rDynamic As Range
Dim rMax As Range
Dim rMin As Range

Set rDynamic = Me.Range("A1")
Set rMax = Me.Range("B1")
Set rMin = Me.Range("C1")

If Not Intersect(Target, rDynamic) Is Nothing Then
    If rDynamic.Value < rMin.Value Then rMin.Value = rDynamic.Value
    If rDynamic.Value > rMax.Value Then rMax.Value = rDynamic.Value
End If

And test it out.并测试一下。 To save the workbook, you'll need to use the .xlsm file format, and you will also need to enable macros (Excel should prompt you to enable or disable macros after saving, closing, and reopening the workbook).要保存工作簿,您需要使用 .xlsm 文件格式,并且还需要启用宏(Excel 应在保存、关闭和重新打开工作簿后提示您启用或禁用宏)。

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

相关问题 在 excel 中找到最大值或最小值,有条件 - find max or min in excel, with conditions 如何在Excel中查找最大值并返回相邻单元格 - How to find max and return adjacent cell in Excel 如何在Excel中的字母数字数据数组中查找最大值和最小值? - How to find max and min in an alphanumeric data array in Excel? 如何在Excel中找到多个组的最大值和最小值? - How do I find the max & min values of multiple groups in an Excel? Excel VBA根据对应范围的最小值到最大值查找范围内的单元格地址 - Excel VBA Find cell address in range based on min to max value of correspoding range 如何从下拉列表中计算单元格的平均值、最小值、最大值以及它在 Excel 中的变化 - How can I calculate the average, min, max, range for a cell from a dropdown and it changes in Excel Excel MAX/MIN 但仅当相对单元大于 0 - Excel MAX/MIN but only if opposing cell is greater than 0 Excel VBA:如何在忽略错误单元格的同时查找范围的最大值/最小值 - Excel VBA: How to find max/min of a range while ignoring error cells 如何在Excel中使用sumifs()定义最小值和最大值? - How to define min and max with sumifs() in Excel? 如何从从 excel 文件派生的大量字典中的值列表中查找最小值和最大值 - How to find min and max values from list of values in large set of dictionary derived from excel file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM