【发布时间】:2020-05-20 19:14:08
【问题描述】:
我试图在同一列中列出每两个单元格的比较。比如说,我在单元格 A1、A2、A3、..、A11 中有一些值。我正在尝试创建一个表格,使得每个单元格中都包含两个 Ai 和 Aj 的最小值(i 不等于 j)。即 min(Ai,Aj)=x。但是,我设法写了一些东西来帮助我将 A1 与其他 Ai 进行比较。每次,我都需要更改我写的内容,以便将 A2 与其他单元格(A1 除外)进行比较。我怎样才能设法获得一次列表?提前致谢。
这就是我运行代码时发生的情况。
这是我想要得到的。
Sub comparisonfunction2()
Dim ds As Long ' number of files
Dim i As Long 'loop variable
Range("A1").Select
ds = 12
yp = Sheets("Sheet1").Range("a1").CurrentRegion.EntireRow.Count
For i = 2 To ds
If Cells(2, 1) < Cells(i + 1, 1) Then
Cells(2, 1).Select
Selection.Copy
Cells(i + 1, 5).Select
ActiveSheet.Paste
Else
Cells(i + 1, 1).Select
Selection.Copy
Cells(i + 1, 5).Select
ActiveSheet.Paste
End If
Next
End Sub
【问题讨论】:
-
我猜你可以用公式而不是使用 VBA (?)
-
怎么回事?如果你的意思是使用 min 函数,我需要输入 55 次。