Data Validation or Macro to prevent Duplicate up to Vacation days

hajiali

Well-known Member
Joined
Sep 8, 2018
Messages
624
Office Version
  1. 2016
Platform
  1. Windows
In sheet "Employee List" I have employee numbers and first and last name followed by number of Vacation each employee has. Ex

EMPLOYEE NUMBERFIRST NAMELAST NAMEVACATION DAYS
156631TOMSMITH15
54263SARAPARKER12
254264PETERHAYES3
21458KIMCLARK6
122354MATTWADE10
32455LIZMORRIS20
35663JOHNMILLER18
54531JENNYPARKER17
325486JOEPHILLIPS20

On my Vacation sheet I have days for the whole year in column A to the right from column B-L of that I will enter the Employee number to assign them a vacation day. What I need is Data Validation or Macro that will prevent me from Entering the Employee number more than Vacation days. and if I do, Message me with "The employee exceed the number of Vacation days".

Ex. Using the table above the Sheet it should only allow me to enter Peters Employee number in Vacation sheet 3 times, Matt employee number 10 times, JOE employee number 20 times in so on, in the range B2-L636

any suggestion is greatly appreciated.
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
First I turned the range into a table, not sure if you did that step already or not.

Then I created a dynamic range for your employee number column by going into name manager and entering the following formula. I named the range 'emp'.

=OFFSET(Sheet1!$A$2,0,0,COUNTA(Sheet1!$A:$A)-1)

Then, select all of the employee numbers, not the header row, add data validation, select custom, then add the following formula.

=COUNTIF(Emp,A1)=1

Should do the trick.
 
Upvote 0
Thanks Irobbo314 I just tired it on a new workbook and still didnt prevent me from entering the employee number more than the Vacation Days. How does it refer to the Vacation days column? Which Table do i Convert to a Table the range with employee numbers, name, and vacation days, or the Vacation sheet or both?
 
Upvote 0
Sorry, I misunderstood the question. I'll post back later.
 
Upvote 0
So, you can do the same thing with setting up the dynamic ranges if you want. In this example I'm just putting in the formula you will need to add to the custom data validation formula. Hopefully I am understanding it correctly this time. The table on the right illustrates where you are assigning the days off, and the column 'DV formula' has the formula that you will plug into the data validation.

Also, this is all on 1 page for simplicity sake. You might need to adjust the formula to match your sheet names.

Book1
BCDEFGHIJ
1EMPLOYEE NUMBERFIRST NAMELAST NAMEVACATION DAYSEployeeDateDV Formula
2156631TOMSMITH1525426411/24/2019True
354263SARAPARKER1225426411/25/2019True
4254264PETERHAYES325426411/26/2019True
521458KIMCLARK625426411/27/2019False
6122354MATTWADE10
732455LIZMORRIS20
835663JOHNMILLER18
954531JENNYPARKER17
10325486JOEPHILLIPS20
Sheet1
Cell Formulas
RangeFormula
J2:J5J2=COUNTIF($H$2:H2,H2)<=INDEX(Sheet1!$E$2:$E$10,MATCH(H2,Sheet1!$B$2:$B$10,0))
 
Upvote 0
Hey Irobbo314 Thank you for your help. Just had to alter the Formula to work with my sheets and range. Works great!!! thanks :)
 
Upvote 0

Forum statistics

Threads
1,214,972
Messages
6,122,530
Members
449,088
Latest member
RandomExceller01

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