Macro to Find the Largest and Smallest numbers


Find the Largest number in a selection


Sub LargetstNumber()
Dim X As Double, Y As Range
Set Y = Selection
X = WorksheetFunction.Max(Y)
MsgBox X
End Sub

Find the Smallest number in a selection


Sub SmallestNumber()
Dim X As Double, Y As Range
Set Y = Selection
X = WorksheetFunction.Min(Y)
MsgBox X
End Sub

Highlight the Largest number in a selection


Sub HighlightLargestNumber()
Dim X As Range
For Each X In Selection
If X = WorksheetFunction.Max(Selection) Then
X.Interior.ColorIndex = 6
End If
Next X
End Sub

Highlight the Smallest number in a selection


Sub HighlightSmallestNumber()
Dim X As Range
For Each X In Selection
If X = WorksheetFunction.Min(Selection) Then
X.Interior.ColorIndex = 8
End If
Next X
End Sub

Display the Largest and Smallest number in a selection


Sub LargeAndSmallNumbers()
Dim X As Double, Y As Double, Z As Range
Set Z = Selection
X = WorksheetFunction.Max(Z)
Y = WorksheetFunction.Min(Z)
MsgBox "Largest Number is " & X & " and the Smallest Number is " & Y
End Sub

How to use codes shared here?