简体   繁体   English

Excel,最小/最大宏不同范围

[英]Excel, Min/Max macro different range

I am trying to develop hopefully a short macro for someone not too good with code for the following. 我希望为不太熟悉以下代码的人开发一个简短的宏。

I have a file similar to the attached but much much bigger. 我有一个类似于附件的文件,但更大。

For those wondering its FMEA scoring. 对于那些想知道其FMEA得分的人。

I want to take the maximum value of each set of yellow cells * the value of the blue cell * minimum value of the red cells and display just that value in the green cell. 我想取每组黄色单元格的最大值*蓝色单元格的值*红色单元格的最小值,然后在绿色单元格中仅显示该值。

For the amount I have listed i appreciate its easy just to write the formula in. But as I said the file itself is much larger, and as I have tried to show the columns are all different lengths so i cant just look at say 5 rows and copy the formula down as it will not be in the right place. 对于我列出的数量,我很欣赏仅使用公式即可轻松实现的功能。但是正如我所说的,文件本身要大得多,并且由于我试图显示列的长度都是不同的,所以我不能只看说5行然后将公式复制下来,因为它不会放在正确的位置。

Is there an easy way of doing this? 有一个简单的方法吗? Any help would be appreciated. 任何帮助,将不胜感激。

IMG1

This does assume that 19 is the max number of items in a group. 这确实假定19是组中的最大项目数。

Put this in H2 and copy down: 将其放在H2中并复制下来:

=IF(A2<>"",MAX(C2:INDEX(C:C,AGGREGATE(15,6,ROW(C2:C20)/(C2:C20=""),1)))*E2*MIN(G2:INDEX(G:G,AGGREGATE(15,6,ROW(G2:G20)/(G2:G20=""),1))),"")

If 19 is not the max number in a group change the 20 s to the max number of items per group. 如果组中的最大数量不是19,则将20 s更改为每个组中的最大数量。

在此处输入图片说明

Assuming that there is an open break between each "Title Block", the following should work for you. 假设每个“标题栏”之间都有一个开放的休息时间,则以下内容应为您工作。 It can be entered as a formula, all that needs to be done is create a new macro, and paste the code from below into the code window. 可以将其作为公式输入,只需要做的就是创建一个新的宏,然后将下面的代码粘贴到代码窗口中。

Function minMax(ByVal rRange As Range, MinOrMax As String) As Double
Dim dMin As Double
Dim dMax As Double
Dim lLastRow As Long
Dim ws1 As Worksheet

Set ws1 = ActiveWorkbook.ActiveSheet
lLastRow = ws1.Cells(rRange.Row, rRange.Column).End(xlDown).Row

dMin = ws1.Cells(rRange.Row, rRange.Column).Value
dMax = dMin

For Each cell In rRange.Cells
    If cell.Value < dMin Then dMin = cell.Value
    If cell.Value > dMax Then dMax = cell.Value
Next cell

    If InStr(1, MinOrMax, "min") = 1 Then
        minMax = dMin
    Else
        minMax = dMax
    End If

End Function

To use this custom function, enter into the cell where you want the value as "=minMax(B1:B10, "min")" where the second argument should be either a quoted Min or Max. 要使用此自定义函数,请在您想要将值设置为“ = minMax(B1:B10,“ min”)“的单元格中输入,其中第二个参数应为加引号的Min或Max。 Typing "Min" will yield the minimum of the range and "Max" will yield the maxvalue of the range. 输入“ Min”将产生范围的最小值,而“ Max”将产生范围的最大值。 This function will support unlimited arguments and is case insensitive. 此函数将支持无限的参数,并且不区分大小写。

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

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