Question

I have an Excel spreadsheet in which one column I am entering and engine hours daily. I need to set a VBA code which will act as a warning system to get the engine serviced. I would like the cell to change colour to amber at say 300, a darker orange at 400 and red at 500. I also need it to generate an email at 500. The problem I have is that the column will always increase in value. Once the email is sent at 500, it will need to reset to 800, 900 and 1000 and so on. Is this at all possible to do?

Thanks in advance. Trace

Was it helpful?

Solution

As per my comment earlier you could accomplish this with a formula based conditional format:

enter image description here

To have an email send automatically you could modify the following VBA to your specifications:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim oApp As Object
Dim oMail As Object
If Target.Column = 1 Then 'If the change was made in your entry column
    If Target.Value Mod 500 = 0 Then
        Set oApp = CreateObject("Outlook.Application")
        Set oMail = oApp.CreateItem(0)
            With oMail
                .To = "YouRecipient@TheirDomain.com, Sample@Gmail.com"
                .Subject = "Engine Service Needed"
                .Body = "The engine mileage is currently at " _
                        + CStr(Target.Value) _
                        + " Miles And Needs to be Serviced"
                .Display 'You can replace the word display with the word send if you don't want to preview
            End With
    End If
End If
End Sub

Update From Comment:

For Amber change the formula to `=MOD(A1,500)>0`
For darker orange use `=MOD(A1,500)>300`
And for Red use `=OR(MOD(A1,500)>400,MOD(A1,500)=0)`
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top