在Excel中如何用另一个值替换最小值

huangapple go评论82阅读模式
英文:

How to replace the minimum value with another value in excel

问题

你可以使用以下公式来实现你的需求:

=IF(A1<=B1,MAX(MIN(A1:C1),D1),MAX(MIN(A1:C1),D1))

将这个公式应用于你的前100行数据,它将会替换A1、B1和C1中的最小值为它们和D1之间的最大值。不需要创建新的列,最小值会被直接替换。

英文:

Say I have numerical values in A1, B1, C1, D1. I want to replace the minimum of the values in A1, B1, C1, with the maximum between this minimum and D1. Do you have any ideas on how to do that?

For example, say that the values in the cells A1, B1, C1, D1 are respectively

1 2 3 4

I want to turn it into

4 2 3 4

I would like to do this for the first 100 rows. Also, I do not want to create a new column, I want the minimum value to be replaced.

So far I figured out the function ADDRESS(ROW(),MATCH(MIN(A1:C1),A1:C1,0),1)
which gives me the cell number of the cell with the minimum value. Now I just need to figure out how to substitute the value in the cell with the maximum between this value and the value in D1.

答案1

得分: 2

Here is the translated content:

给定你在A1:D1范围内

将以下公式添加到A2。

=IF(A1=MIN($A1:$D1),MAX($A1:$D1),A1)

然后将其拉伸复制到D2。

你不能使用公式替换原始值,因为那会创建循环引用。你也不能使用公式修改输入数据,那会导致无限循环计算。

你可以在多行上使用这种方法,只需将公式复制到多个输出行,例如在另一个工作表上。

例如,如果你的数据工作表命名为'Sheet1',你可以将这个公式放在Sheet2:A1

=IF(Sheet1!A1=MIN(Sheet1!$A1:$D1);MAX(Sheet1!$A1:$D1);Sheet1!A1)

然后将其向右拉伸4个单元格,向下100行。

在Excel中如何用另一个值替换最小值

英文:

Given you have the range in A1:D1

Add the formula to A2.

=IF(A1=MIN($A1:$D1),MAX($A1:$D1),A1)

And stretch-copy it to D2.

在Excel中如何用另一个值替换最小值

You cannot replace the original value using formula, it would create a circular reference. You cannot modify the input data using formula - that would be an infinite loop of calculations.

You can use this approach for multiple rows too, you just need to copy the formulas to multiple output rows e.g. on another worksheet.

E. g. if your data sheet is named Sheet1, you put this formula to Sheet2:A1

=IF(Sheet1!A1=MIN(Sheet1!$A1:$D1);MAX(Sheet1!$A1:$D1);Sheet1!A1)

And stretch it 4 cells to the right and 100 rows downwards.

在Excel中如何用另一个值替换最小值

答案2

得分: 0

是的,无法创建循环引用。
尝试使用这个宏。将其复制到工作表的VBE代码模块中并运行。
有效数据从第一行开始,如果不是,请更改i = 1短语中的相应行号值。

Sub Somemacro()
lastrow = Cells(Rows.Count, 1).End(xlUp).Row
For i = 1 To lastrow
mincell = WorksheetFunction.Min(Range("A" & i & ":C" & i))
mincellcol = WorksheetFunction.Match(mincell, Range("A" & i & ":C" & i), 0)
If Cells(i, 4) > Cells(i, mincellcol) Then
Cells(i, mincellcol) = Cells(i, 4)
End If
Next i
End Sub
英文:

Yes, cannot create circular reference.
Try this macro. Copy it into the sheet's VBE code module and run.
Valid datas start in the first row, if not change the value to the corresponding row number in the i = 1 phrase.

Sub Somemacro()
lastrow = Cells(Rows.Count, 1).End(xlUp).Row
For i = 1 To lastrow
mincell = WorksheetFunction.Min(Range(&quot;A&quot; &amp; i &amp; &quot;:C&quot; &amp; i))
mincellcol = WorksheetFunction.Match(mincell, Range(&quot;A&quot; &amp; i &amp; &quot;:C&quot; &amp; i),0)
If Cells(i, 4) &gt; Cells(i, mincellcol) Then
Cells(i, mincellcol) = Cells(i, 4)
End If
Next i
End Sub

huangapple
  • 本文由 发表于 2023年5月15日 12:38:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/76250917.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定