How to use a macro to determine which number is the highest?


can you help me with my presentation? I need a macro that finds the highest number (or numbers) in the labels 1 to 4 and write it to me along with a letter (which belongs to a number) into the blue rectangle in the form "number: 51, letter: A"
If several numbers are the same (they can also change) should be a blue rectangle for example write: "numbers: 51, 51, letters: A, D
Numbers, like letters - the fourth most
Look for attachment - to illustrate, I think it will be easier to understand.
Thanks in advance for your help.


Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris BottomleySoftware Quality Lead EngineerCommented:
Try the following:

Sub biggie()
Dim nums(1 To 4) As Integer
Dim arrNumbers() As String
Dim arrAlpha() As String
Dim intmax As Integer
Dim strMax As String
Dim intCycle As Integer
Dim intArraySize As Integer

    For intCycle = 1 To 4
        nums(intCycle) = CInt(Application.ActivePresentation.Slides(1).Shapes("Label" & intCycle).OLEFormat.Object.Caption)
        If nums(intCycle) > intmax Then intmax = nums(intCycle)
    For intCycle = 1 To 4
        If nums(intCycle) = intmax Then
            ReDim Preserve arrNumbers(0 To intArraySize)
            ReDim Preserve arrAlpha(0 To intArraySize)
            arrNumbers(intArraySize) = intmax
            arrAlpha(intArraySize) = Chr(Asc("A") + intCycle - 1)
            intArraySize = intArraySize + 1
        End If
    Application.ActivePresentation.Slides(1).Shapes("the_highest_number").TextFrame.TextRange.Text = "Numbers: " & Join(arrNumbers, ", ") & ", " & "Letters: " & Join(arrAlpha, ", ")
End Sub

Open in new window

Chris BottomleySoftware Quality Lead EngineerCommented:
If there is a chance of the letters being modified then you could replace:

            arrAlpha(intArraySize) = Chr(Asc("A") + intCycle - 1)
            arrAlpha(intArraySize) = Application.ActivePresentation.Slides(1).Shapes(Chr(Asc("A") + intCycle - 1)).TextFrame.TextRange.Text

In the supplied code


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Thomas_MeyerAuthor Commented:
Macro works perfectly fine, exactly as I needed!
Thank you.


It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.