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

Hi,

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.

Regards,

TM TEST.ppt
Thomas_MeyerAsked:
Who is Participating?
 
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)
with
            arrAlpha(intArraySize) = Application.ActivePresentation.Slides(1).Shapes(Chr(Asc("A") + intCycle - 1)).TextFrame.TextRange.Text

In the supplied code

Chris
0
 
Chris BottomleySoftware Quality Lead EngineerCommented:
Try the following:

Chris
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)
    Next
    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
    Next
    Application.ActivePresentation.Slides(1).Shapes("the_highest_number").TextFrame.TextRange.Text = "Numbers: " & Join(arrNumbers, ", ") & ", " & "Letters: " & Join(arrAlpha, ", ")
End Sub

Open in new window

TEST-3.ppt
0
 
Thomas_MeyerAuthor Commented:
@Chris
Macro works perfectly fine, exactly as I needed!
Thank you.

Regards,

TM
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.