VBA MOD01 Project Activity Show top 3 value on Message box based on range selected

 Project Activity Show top 3 value

Dim myRange As Range

Dim Top1 As Double, Top2 As Double, Top3 As Double

Dim msg As Long

On Error GoTo leave


Set myRange = Application.InputBox(Prompt:="Select the range of no to get top 3 values", _

Title:="Top3..", Type:=8)

If Application.WorksheetFunction.Count(myRange) > 2 Then



    Top1 = Excel.WorksheetFunction.Large(myRange, 1)

    Top2 = Excel.WorksheetFunction.Large(myRange, 2)

    Top3 = Excel.WorksheetFunction.Large(myRange, 3)

    

    msg = MsgBox _

    (Prompt:="Here is the top three values" & vbNewLine & "Top1" _

    & " " & Top1 & vbNewLine & "Top2" & " " & Top2 & _

    vbNewLine & "Top3" & " " & Top3, _

    Title:="Here is the Top 3 values", Buttons:=vbOKOnly)

Else


MsgBox "please select at least 3 cells with numbers", vbInformation


leave:


End If


End Sub







Comments

Popular posts from this blog

VBA01 Copy Resize Variably Sized Ranges

VBA MOD01 Passing Arguments to sub procedures (ByRef , By Val)

PY MOD01 Lecture 01