Message Box when cell value becomes largest in range

Ironman

Well-known Member
Joined
Jan 31, 2004
Messages
1,069
Office Version
  1. 365
Platform
  1. Windows
Hi

Sheet 'Training Log' D8413:D8657 contains values (not formulas) that are being added to daily, down to D8779.

I need a msgbox to pop up once only, when a value is added that becomes the new maximum value in the range D8413:D8779 (and then pop up again the next time a new maximum value is input).

Many thanks!
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Try this. Open a copy of your workbook. On your Training Log sheet, right click on the sheet tab on the bottom and select View Code. Paste this code in the window that opens:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim MyData As Variant, OldMax As Double

    If Intersect(Target, Range("D8413:D8779")) Is Nothing Then Exit Sub
    
    MyData = Range("D8413:D8779").Value
    MyData(Target.Row - 8413 + 1, 1) = ""
    OldMax = WorksheetFunction.Max(MyData)
    If Target.Value > OldMax Then
        MsgBox "You just entered a new max value: " & Target.Value & vbCrLf & "The old max was: " & OldMax
    End If
    
End Sub

Close the VBA editor (Alt-Q or the red X). Try it out.
 
Upvote 0
Superb Eric, that works perfectly, thank you!

Can I just ask you if it's possible for you to also include C8413:C8779 in the code and for a different msgbox to be created for each of the ranges (eg. "maximum distance achieved" for C8413:C8779 and "maximum time achieved" for D8413:D8779), or would I need to copy and add the above to the Worksheet_Change and change the range?

Thanks again Eric!
 
Upvote 0
OK, try this:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim MyData As Variant, OldMax As Double

    If Not Intersect(Target, Range("C8413:C8779")) Is Nothing Then
        MyData = Range("C8413:C8779").Value
        MyData(Target.Row - 8413 + 1, 1) = ""
        OldMax = WorksheetFunction.Max(MyData)
        If Target.Value > OldMax Then MsgBox "Maximum distance achieved"
    End If
    
    If Not Intersect(Target, Range("D8413:D8779")) Is Nothing Then
        MyData = Range("D8413:D8779").Value
        MyData(Target.Row - 8413 + 1, 1) = ""
        OldMax = WorksheetFunction.Max(MyData)
        If Target.Value > OldMax Then MsgBox "Maximum time achieved"
    End If
    
End Sub
 
Upvote 0
Solution
Ah, that's fantastic! Thank you ever so much Eric :)
 
Upvote 0

Forum statistics

Threads
1,214,834
Messages
6,121,871
Members
449,054
Latest member
juliecooper255

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top