在excel文档里新建一个宏Number_comparison,编辑这个宏,执行这个宏就可以的。
Sub Number_comparison()
Dim X, Y As Integer
X = InputBox(Prompt:="输入X的值:")
Y = InputBox(Prompt:="输入Y的值:")
If X >= Y Then
MsgBox Prompt:="输入较大的数是:X = " & X
Else
MsgBox Prompt:="输入较大的数是:Y = " & Y
End If
End Sub
通用值比较函数:
Public Function 数值比较(Byval N1, ByVal N2, Option ByVal 取大值 As Boole = True)
If 取大值 = True then
If N1>N2 then
数值比较=N1
Else
数值比较=N2
Endif
Else
If N1>N2 then
数值比较=N2
Else
数值比较=N1
Endif
EndIf
End function