[英]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.