Msgbox to return sum of 2 cells

mulholm

New Member
Joined
Jul 2, 2018
Messages
49
Hi,

I am looking for some help to expand the formula i have. On the table below i want a message box to appear when column D is higher then column C which i have managed to code myself. However where i am struggling with is that i want the message box to display how much higher D is than C.

Paid Breaks
NameShift (Hours)Break Time AvailableBreak Time Used
Agent17.0000:16:480:18:17
Agent27.0000:16:480:16:14
Agent37.0000:16:480:11:23
Agent46.0000:14:240:14:57
Agent57.0000:16:480:16:43
Agent64.0000:09:360:10:53
Agent77.0000:16:480:18:20
Agent87.0000:16:480:15:11
Agent97.0000:16:480:16:24
Agent107.0000:16:480:08:10
Agent117.0000:16:480:16:29

<colgroup><col><col><col><col></colgroup><tbody>
</tbody>

Just now i have the below code:

Private Sub DataAnalysis()


Dim Overbreaks As Integer


For i = 3 To 13


If Sheet1.Range("D" & i).Value > Sheet1.Range("C" & i).Value Then

Sheet1.Range("D" & i).Select

Overbreaks = ActiveCell.Value + Sheet1.Range("C" & i)

MsgBox (Overbreaks)

End If


Next


End Sub

However this doesnt seem to work.

I also want in the message box to return "Agent name (Column A) was over their break by Overbreaks (Column D - Column C)"
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Try this:

Code:
For I = 3 To 13
    If Sheet1.Range("D" & I).Value > Sheet1.Range("C" & I).Value Then
        MsgBox Sheet1.Range("A" & I).Value & " was over their break by " & _
            Format(Sheet1.Range("D" & I).Value - Sheet1.Range("C" & I).Value, "hh:mm:ss")
    End If
Next
 
Upvote 0
worked perfectly.

is there a way for it to all appear on the 1 msgbox instead of clicking ok then the next one appears.
Also can you e-mail the output of the msgbox once it's generated?
 
Last edited:
Upvote 0
Something like:

Code:
For i = 3 To 13
    If Sheet1.Range("D" & i).Value > Sheet1.Range("C" & i).Value Then
        If Len(myMessage) = 0 Then
            myMessage = Sheet1.Range("A" & i).Value & " was over their break by " & _
                Format(Sheet1.Range("D" & i).Value - Sheet1.Range("C" & i).Value, "hh:mm:ss")
        Else
            myMessage = myMessage & vbLf & Sheet1.Range("A" & i).Value & " was over their break by " & _
                Format(Sheet1.Range("D" & i).Value - Sheet1.Range("C" & i).Value, "hh:mm:ss")
        End If
    End If
Next
If Len(myMessage) > 0 Then MsgBox myMessage

Look online for email example code and have myMessage as the body.
 
Upvote 0

Forum statistics

Threads
1,214,924
Messages
6,122,294
Members
449,077
Latest member
Rkmenon

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