Date data validation formula

Ceallach

New Member
Joined
Sep 14, 2019
Messages
20
Sorry, I kind of forget what you really mean by occur within 7 days, does it include the same day?
So if green room X with green room Y occur in the same day it's not a conflict?
Yes that's right. It's basically use of some equipment related to that room so it's not a conflict at all, can be used at anytime separate.
 

Some videos you may like

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

Akuini

Well-known Member
Joined
Feb 1, 2016
Messages
2,559
Office Version
365
Platform
Windows
Ok, so the conflict only happens if for the same second criteria (x,y or z) user pick whole venue & any colored room within 7 days?
If user doesn't pick whole venue then there is no situation that will cause conflict, is it correct?

Another thing, is it possible that the user inserting duplicate entries? do you need to prevent it?
 

Ceallach

New Member
Joined
Sep 14, 2019
Messages
20
Ok, so the conflict only happens if for the same second criteria (x,y or z) user pick whole venue & any colored room within 7 days?
If user doesn't pick whole venue then there is no situation that will cause conflict, is it correct?

Another thing, is it possible that the user inserting duplicate entries? do you need to prevent it?

Yep conflict if they have the same criteria within 7 days. Conflict for whole venue with the same criteria as any other room within 7 days.

If there's no whole venue used within the 7 days then yes, no situation will cause conflict unless somebody tries to select the exact same venue and criteria e.g. Green Room X for 2nd Oct and Green Room X for 3rd Oct would conflict. Any other combination of room and criteria is fine.

Duplicate entries isn't a likely issue, there are further columns where they specify the person who has booked it etc so it would be obvious if there was an issue there. And it still isn't very many events per month.
 

Akuini

Well-known Member
Joined
Feb 1, 2016
Messages
2,559
Office Version
365
Platform
Windows
Ok, try this:

Code:
[FONT=Lucida Console][COLOR=Royalblue]Private[/COLOR] [COLOR=Royalblue]Sub[/COLOR] Worksheet_Change([COLOR=Royalblue]ByVal[/COLOR] Target [COLOR=Royalblue]As[/COLOR] Range)
[COLOR=Royalblue]If[/COLOR] Target.Cells.CountLarge <> [COLOR=Brown]1[/COLOR] [COLOR=Royalblue]Then[/COLOR] [COLOR=Royalblue]Exit[/COLOR] [COLOR=Royalblue]Sub[/COLOR]
    
    [COLOR=Royalblue]If[/COLOR] [COLOR=Royalblue]Not[/COLOR] Intersect(Target, Range([COLOR=Darkcyan]"A1:A20"[/COLOR])) [COLOR=Royalblue]Is[/COLOR] [COLOR=Royalblue]Nothing[/COLOR] [COLOR=Royalblue]Then[/COLOR]
    
        [COLOR=Royalblue]If[/COLOR] Target.Offset(, [COLOR=Brown]1[/COLOR]) = [COLOR=Darkcyan]""[/COLOR] [COLOR=Royalblue]Or[/COLOR] Target.Offset(, [COLOR=Brown]2[/COLOR]) = [COLOR=Darkcyan]""[/COLOR] [COLOR=Royalblue]Then[/COLOR]
            MsgBox [COLOR=Darkcyan]"You need to pick a Venue and a criteria"[/COLOR]
            Application.EnableEvents = False
            Target.ClearContents
            Application.EnableEvents = True
            [COLOR=Royalblue]Exit[/COLOR] [COLOR=Royalblue]Sub[/COLOR]
        [COLOR=Royalblue]End[/COLOR] [COLOR=Royalblue]If[/COLOR]

        
        [COLOR=Royalblue]Dim[/COLOR] c [COLOR=Royalblue]As[/COLOR] Range, flag [COLOR=Royalblue]As[/COLOR] [COLOR=Royalblue]Boolean[/COLOR], tx [COLOR=Royalblue]As[/COLOR] [COLOR=Royalblue]String[/COLOR], crt [COLOR=Royalblue]As[/COLOR] [COLOR=Royalblue]String[/COLOR]
        [COLOR=Royalblue]If[/COLOR] IsDate(Target) [COLOR=Royalblue]Then[/COLOR]
            flag = True: tx = [COLOR=Darkcyan]""[/COLOR]: ven = Target.Offset(, [COLOR=Brown]1[/COLOR]).Value: crt = Target.Offset(, [COLOR=Brown]2[/COLOR]).Value
            [COLOR=Royalblue]For[/COLOR] [COLOR=Royalblue]Each[/COLOR] c In Range([COLOR=Darkcyan]"A1:A20"[/COLOR])
                [COLOR=Royalblue]If[/COLOR] Len(c) > [COLOR=Brown]0[/COLOR] [COLOR=Royalblue]And[/COLOR] IsDate(c) [COLOR=Royalblue]And[/COLOR] c.Address <> Target.Address [COLOR=Royalblue]Then[/COLOR]
                    [COLOR=Royalblue]If[/COLOR] c.Offset(, [COLOR=Brown]2[/COLOR]) = crt [COLOR=Royalblue]And[/COLOR] (ven = [COLOR=Darkcyan]"Whole Venue"[/COLOR] [COLOR=Royalblue]Or[/COLOR] c.Offset(, [COLOR=Brown]1[/COLOR]) = [COLOR=Darkcyan]"Whole Venue"[/COLOR] [COLOR=Royalblue]Or[/COLOR] c.Offset(, [COLOR=Brown]1[/COLOR]) = ven) [COLOR=Royalblue]Then[/COLOR]
                        [COLOR=Royalblue]If[/COLOR] Abs(DateDiff([COLOR=Darkcyan]"d"[/COLOR], [COLOR=Royalblue]CDate[/COLOR](Target), [COLOR=Royalblue]CDate[/COLOR](c))) < [COLOR=Brown]7[/COLOR] [COLOR=Royalblue]Then[/COLOR]
                            tx = tx & c & [COLOR=Darkcyan]" : "[/COLOR] & c.Offset(, [COLOR=Brown]1[/COLOR]) & [COLOR=Darkcyan]" : "[/COLOR] & crt & vbLf
                            flag = False
                        [COLOR=Royalblue]End[/COLOR] [COLOR=Royalblue]If[/COLOR]
                    [COLOR=Royalblue]End[/COLOR] [COLOR=Royalblue]If[/COLOR]
                [COLOR=Royalblue]End[/COLOR] [COLOR=Royalblue]If[/COLOR]
            [COLOR=Royalblue]Next[/COLOR]
            
            [COLOR=Royalblue]If[/COLOR] flag = False [COLOR=Royalblue]Then[/COLOR]
                    MsgBox [COLOR=Darkcyan]"Pick another date."[/COLOR] & vbLf & [COLOR=Darkcyan]"This has been allocated:"[/COLOR] & vbLf & tx, vbCritical
                    Application.EnableEvents = False
                    Target.ClearContents
                    Application.EnableEvents = True
                    [COLOR=Royalblue]Exit[/COLOR] [COLOR=Royalblue]Sub[/COLOR]
            [COLOR=Royalblue]End[/COLOR] [COLOR=Royalblue]If[/COLOR]
        [COLOR=Royalblue]Else[/COLOR]
            MsgBox [COLOR=Darkcyan]"You need to insert a date"[/COLOR]
                    Application.EnableEvents = False
                    Target.ClearContents
                    Application.EnableEvents = True

        [COLOR=Royalblue]End[/COLOR] [COLOR=Royalblue]If[/COLOR]
        
    [COLOR=Royalblue]End[/COLOR] [COLOR=Royalblue]If[/COLOR]
[COLOR=Royalblue]End[/COLOR] [COLOR=Royalblue]Sub[/COLOR][/FONT]
 

Forum statistics

Threads
1,089,594
Messages
5,409,179
Members
403,256
Latest member
Viq

This Week's Hot Topics

  • help please
    SORRY NOT ANY GOOD AT EXCEL SO HELP WOULD BE MUCH APPRECIATED this formula is in a sheet called ignore...
  • two formulas needed
    Hello, I'll try my best to explain this: First formula needed in Sheet1 cell A2: If Sheet1 cell B2 = Sheet2 cell B2 then return a 1. If not then...
  • Dynamic Counts
    Good afternoon, we are tidying up some data & the data seems to be growing quicker than we are tidying it up! What we confirm (by reviewing it...
  • Help Excel formula eliminate duplicate values and keep only 2 identical rows.
    as picture below column A has a duplicate value. but the values are not the same as the rule. sometimes 4 rows, sometimes 10 rows or 7 or 9...
  • Macro Compile Error Sub or Function not defined
    Hello, I am trying to run macros from a validation list, all macros have been created and run perfectly on there own but I'm getting a compile...
  • Last row combined with Current Region VBA
    I'm generally happy finding the last row of data through something like Lastrow = Cells(Rows.Count, "D").End(xlUp) but I don't always receive data...
Top