VBA怎么比较3个单元格数值的大小.如果,最大返回2,最小返回0,中间返回1,返回值在别的单元格中输出

要比较的输入单元格B9,C9,D9。对应输出的单元格E9,F9,G9,单元格是固定的
数值可以是小数跟整数比较 代码怎么写

第1个回答  2012-04-12
Sub 比较()
Dim a(3)
For i = 0 To 2
a(i) = Cells(9, i + 2)
Next i
m = a(0)
n = a(0)
For i = 1 To 2
If m < a(i) Then m = a(i)
If n > a(i) Then n = a(i)
Next i
For i = 0 To 2
If a(i) = m Then Cells(9, i + 5) = 2
If a(i) = n Then Cells(9, i + 5) = 0
If a(i) <> m And a(i) <> n Then Cells(9, i + 5) = 1
Next i
End Sub
相似回答
大家正在搜