Macro Message Box Help

GSA_Tanya

New Member
Joined
Dec 19, 2013
Messages
9
Im trying to create a time sheet for work. I have created it so that one column auto populates with each persons expected hours, and a hidden column next to it shows the difference in the hours that they were supposed to work and what they actually worked. I would like a pop up message to warn the employee that they have worked additional or not enough hours and need to claim them. However when I create a message box it just pops up everytime anything gets entered, I've tried data validation and creating a simple macro. But I'm not really familiar with creating macro's. Can someone please help me create a message box that pops up only if the data they have entered doesn't equal 0 difference?
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
You did not specify which columns, so assume the scheduled hours are in column B beginning in B2, The difference in hours in hidden column C, The acvtual hours entered by the employee in Column D. beginning in C2. Further assuming that you want this message to pop up as soon as an emplyee enters the hours worked. The code below is a Worksheet_Change event code and should be copied and pasted into the worksheet code module. To access the code module, right click the sheet name tab, then click "View Code" in the pup up menu.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If Target.Offset(0, -2).Resize(1, 3) = "" Then Exit Sub
If Not Intersect(Target, Range("D:D")) Is Nothing Then
    If Target.Value > Target.Offset(0, -2).Value Then
        MsgBox "You have exceeded the scheduled hours by " & Target.Offset(0, -1).Value & " hours."
    ElseIf Target.Value < Target.Offset(0, -2).Value Then
        MsgBox "You are short of the scheduled hours by " & Target.Offset(0, -1).Value & " hours."
    End If
End If
End Sub
Maybe you can work with this to fit your needs.
 
Upvote 0
Thank you for your response. I'm not sure why this isn't working, maybe you can shed some light for me :)
This code has popped up highlighted yellow: If Target.Offset(0, -2).Resize(1, 3) = "" Then Exit Sub
My sheet is set up so that I have :
Total hours worked (Q8:Q24) Expected Hours - with VLookup to employee (R8:R24), Discrepancy to be claimed (S8:S24)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,173
Members
451,543
Latest member
cesymcox

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