VBA中比较3个数值大小3个数字可以是正数也可以是负数,但是必须把负数当成正数来比较大小输出结果012表示

VBA中比较3个数值大小3个数字可以是正数也可以是负数,但是必须把负数当成正数来比较大小输出结果012表示
比较的结果在后边输出0最小,1中间,2最大.最好能加上颜色正数的结果是蓝色,负数的结果红色
刁谗公主 1年前 已收到1个回答 举报

三个ee指航向 幼苗

共回答了7个问题采纳率:71.4% 举报

Sub 比较大小()
Dim a,b,c
a = Abs([a1].Value)
b = Abs([b1].Value)
c = Abs([c1].Value)
Range("D1").NumberFormatLocal = "@"
If a > b And a > c And b > c Then [d1] = "210"
If b > a And b > c And a > c Then [d1] = "120"
If c > a And c > b And a > b Then [d1] = "102"
If a > b And a > c And c > b Then [d1] = "201"
If b > a And b > c And c > a Then [d1] = "021"
If c > a And c > b And b > a Then [d1] = "012"
If a = [a1].Value Then
Range("A1").Interior.ColorIndex = 42
Range("A1").Font.ColorIndex = 41
Else
Range("A1").Interior.ColorIndex = 40
Range("A1").Font.ColorIndex = 3
End If
If b = [b1].Value Then
Range("b1").Interior.ColorIndex = 42
Range("b1").Font.ColorIndex = 41
Else
Range("b1").Interior.ColorIndex = 40
Range("b1").Font.ColorIndex = 3
End If
If c = [c1].Value Then
Range("c1").Interior.ColorIndex = 42
Range("c1").Font.ColorIndex = 41
Else
Range("c1").Interior.ColorIndex = 40
Range("c1").Font.ColorIndex = 3
End If
End Su

1年前

2
可能相似的问题
Copyright © 2024 YULUCN.COM - 雨露学习互助 - 17 q. 0.074 s. - webmaster@yulucn.com