I want the first VBA code 'Sub HolPubDateCheckStart(dateStart As Date)' after…
- User
I want the first VBA code 'Sub HolPubDateCheckStart(dateStart As Date)' after completing, to call the second VBA code 'Sub SchHodDateCheckStart(dateStart As Date)' and also pass on the 'dateStart As Date' How can I do this.
Sub HolPubDateCheckStart(dateStart As Date) 'check if date is Saturday or Sunday If Weekday(dateStart) = 1 Or Weekday(dateStart) = 7 Then Application.Undo MsgBox "Day entered is Weekend", vbOKOnly, "WEEKEND" Exit Sub End If
' Check if the date is a public holiday Dim ws As Worksheet Set ws = ThisWorkbook.Worksheets("HolCard") Dim holidayRange As Range Set holidayRange = ws.Range("W3:W26") Dim matchResult As Variant matchResult = Application.Match(CLng(dateStart), holidayRange, 0) If Not IsError(matchResult) Then Application.Undo MsgBox "Day entered is a Public Holiday", vbOKOnly, "HOLIDAY" Exit Sub End If ' Check if the date is 14 days before any public holiday Dim holidayCell As Range Dim approachingHoliday As Boolean approachingHoliday = False For Each holidayCell In holidayRange If IsDate(holidayCell.Value) Then ' Ensure the cell contains a valid date If holidayCell.Value > dateStart And holidayCell.Value <= dateStart + 14 Then approachingHoliday = True Exit For End If End If Next holidayCell ' If a holiday is approaching, display the message If approachingHoliday Then MsgBox "A PUBLIC HOLIDAY IS APPROACHING" & vbCrLf & _ "Make sure that your end date" & vbCrLf & _ "is before the Holiday date" & vbCrLf & _ "or Split leave date as required", vbCritical, "HOLIDAY APPROACHING" End IfEnd Sub
Sub SchHodDateCheckStart(dateStart As Date)
' Check if the date is a School holiday Dim ws As Worksheet Set ws = ThisWorkbook.Worksheets("HolCard") Dim holidayRange As Range Set holidayRange = ws.Range("X3:X180") Dim matchResult As Variant matchResult = Application.Match(CLng(dateStart), holidayRange, 0) If Not IsError(matchResult) Then Application.Undo MsgBox "Day entered is a School Holiday", vbOKOnly, "HOLIDAY" Exit Sub End If ' Check if the date is 7 days before any School holiday Dim holidayCell As Range Dim approachingHoliday As Boolean approachingHoliday = False For Each holidayCell In holidayRange If IsDate(holidayCell.Value) Then ' Ensure the cell contains a valid date If holidayCell.Value > dateStart And holidayCell.Value <= dateStart + 7 Then approachingHoliday = True Exit For End If End If Next holidayCell ' If a holiday is approaching, display the message If approachingHoliday Then MsgBox "A SCHOOL HOLIDAY IS APPROACHING" & vbCrLf & _ "Make sure that your end date" & vbCrLf & _ "is before the Holiday date" & vbCrLf & _ "or Split leave date as required", vbCritical, "HOLIDAY APPROACHING" End IfEnd Sub
- Assistant
- User
Can you please change this to a Yes No message. Yes, continue with code, No undo entry and exit sub : If Not IsError(matchResult) Then MsgBox "DAY ENTERED IS A SCHOOL HOLIDAY" & vbCrLf & _ "Do you approve this holiday request", vbOKOnly, "HOLIDAY" Exit Sub End If
- Assistant