Making a rota need a bit of help with a VBA code

inman09

New Member
Joined
Dec 19, 2016
Messages
5
Hey all first time posting here hope i make sense.

Im looking to make a new rota to help reduce confusion and mistakes with colleagues shifts so started making a rota. Im pretty savvy with excell but have never really branched into VBA to further my knowledge but know ill need code to achieve what im after.

Essentially need to be able to populate each week with peoples names but if someone is entered into the rota lets say 4 times it will prompt the user that they have entered this person for to many shifts that week but only have this prompt appear once. I got the box to display but it continues to display no matter whos name i put into the rota, for example Ive put Tom into the rota 4 times the box appears warning me that ive entered him for too many shifts but this was overtime, i then add billy to the rota but the "Youve added Tom too many times this week" will appear again.

My current code is :

Code:
Private Sub Worksheet_Calculate()
    If Range("B1") > 3 Then
        MsgBox "Tom has too many shifts this week unless hes doing extra?"
    End If
End Sub

If thats not made any sense then i apologise, but essentially i just want that warning message to appear once.


Any help greatly apprieciated :)

Tom
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Can you provide an example of your rota? It will help to see what columns or rows the data is in
 
Upvote 0
There are tools you can use to post screen images. They are listed in Section B of this link here: Guidelines for Forum Use.

Also, there is a Test Here forum on this board that you can use to test out these tools to make sure they are working correctly before using them in your question.
 
Upvote 0
[URL="http://
Excel 2010
BCDEFGHI
3Week One
4Date01/01/1900Excel 2010BCDEFGHI3Week One4Date01/01/190002/01/190003/01/190004/01/190005/01/190006/01/19005Res/DaySundayMondayTuesdayWednesdayThursdayFridaySaturday6Res 1,2,37Res 1,2,38Res 59Res 610Kinnon 111Kinnon HCA1213Annual Leave14Training
BCDEFGHI
3Week One
4Date01/01/190002/01/190003/01/190004/01/190005/01/190006/01/1900
5Res/DaySundayMondayTuesdayWednesdayThursdayFridaySaturday
6Res 1,2,3
7Res 1,2,3
8Res 5
9Res 6
10Kinnon 1
11Kinnon HCA
12
13Annual Leave
14Training
Rota
[/URL]
 
Upvote 0
So if an employee's name is listed 4 or more times in cells C6:I11 you want the message to pop-up?
 
Last edited:
Upvote 0
I used the code

Code:
Private Sub Worksheet_Calculate()
    If Range("B1") > 3 Then
        MsgBox "Tom has too many shifts this week unless hes doing extra?"
    End If
End Sub

This will make it pop up with my message but i want it to only display this message once so not re test the IF statement when i type another employees name into the rota cause at present if i have "Tom" in the rota 4 times then close the message and type "Billy" it will pop up again and say youve added Tom to many times this week.
 
Upvote 0
This code will only activate when the B1 is changed and will only count the value that is located in B1:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)    
If Not Intersect(Target, Target.Worksheet.Range("B1")) Is Nothing Then
    If Application.CountIf(Range("B5:H11"), Range("B1").Value) > 3 Then
         MsgBox Range("B1").Value & " has too many shifts this week unless he is doing extra?"
    End If
End If
End Sub
 
Upvote 0
Hey sorry for the late reply wasnt at my computer till this afternoon

Ive tried out this code and im probably doing something wrong but nothing is diplayed when i input Tom more than 4 times. If it makes any difference on the second sheet i have a list of names with COUNTIF's referenced to the rotas and there names so B1 is on another sheet and counts how many toms are in the rota on sheet 1
 
Upvote 0
The code is design to only activate when B1 is changed. What happens if you change cell B1 to Tom (even if it is already labelled as Tom).
 
Upvote 0

Forum statistics

Threads
1,214,614
Messages
6,120,533
Members
448,969
Latest member
mirek8991

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