vba code

kroters

New Member
Joined
Jan 1, 2015
Messages
7
i am after setting up a pop up box when 2 conditions are met.
example- i have shift times on a worksheet ranging from 0700-1630 to 0930-1900.
a cell above the shift times can be changed to 8.5 if they want the holiday.
what i want is a pop up box to show if 8.5 is added to a 0930-1900 day so they know they need to cover their shift.


a b c d e
1 8.5 8.5
2 0700-1630 0700-1630 0700-1630 0700-1630 0700-1630
3 8.5
4 0930-1900 0930-1900 0930-1900 0930-1900 0930-1900
5
6 0800-1730 0800-1730 0800-1730 0800-1730 0800-1730
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Maybe try something like this:

Code:
[COLOR=#0000ff]Private Sub[/COLOR] Worksheet_Change([COLOR=#0000ff]ByVal[/COLOR] Target[COLOR=#0000ff] As [/COLOR]Range)


    [COLOR=#0000ff]If[/COLOR] Target.Value = "8.5" [COLOR=#0000ff]And [/COLOR]Target.Offset(1).Value = "0930-1900" [COLOR=#0000ff]Then[/COLOR]
        MsgBox "You will need to cover your shift!", vbCritical, "Alert!"
[COLOR=#0000ff]    End If[/COLOR]
[COLOR=#0000ff]
[/COLOR]
[COLOR=#0000ff]End Sub[/COLOR]
 
Upvote 0
I would strongly recommend adding the blue lines below. Otherwise, if anybody ever alters more than 1 cell at a time (eg select 2 cells & delete their contents, or copy/paste multiple cells etc) the code will error.

Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
  If Target.Count = 1 Then
    If Target.Value = "8.5" And Target.Offset(1).Value = "0930-1900" Then
      MsgBox "You will need to cover your shift!", vbCritical, "Alert!"
    End If
  End If
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,043
Messages
6,122,812
Members
449,095
Latest member
m_smith_solihull

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