Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
The code below is part of a TimeSheet i have set up.
The code below is to prevent an overlap in job finish/start times, unless "V17".value is selected. Is there a way i can simplify the code to be more efficiently written? I am trying to reduce th size of the file. ((Private Sub Worksheet_SelectionChange(ByVal target As Range) If Range("C8") = "" Then Exit Sub If Range("C11") = "" Then Exit Sub If Range("C11").Value < Range("C8").Value And Range("C9").Value < Range("V17").Value Then MsgBox "There is an overlap in the Times Entered." & vbCrLf & "The next Start Time needs to be equal or greater than the previous Finish Time.", , " ....." Range("C11").ClearContents Range("C11").Select End If If Range("C15") < "" And Range("C15") < Range("C12") And Range("C11").Value < Range("V17").Value Then MsgBox "There is an overlap in the Times Entered." & vbCrLf & "The next Start Time needs to be equal or greater than the previous Finish Time.", , "...." Range("C15").ClearContents Range("C15").Select End If If Range("F8") = "" Then Exit Sub If Range("F11") = "" Then Exit Sub If Range("F11").Value < Range("F8").Value And Range("F9").Value < Range("V17").Value Then MsgBox "There is an overlap in the Times Entered." & vbCrLf & "The next Start Time needs to be equal or greater than the previous Finish Time.", , "...." Range("F11").ClearContents Range("F11").Select End If If Range("F15") < "" And Range("F15") < Range("F12") And Range("F11").Value < Range("V17").Value Then MsgBox "There is an overlap in the Times Entered." & vbCrLf & "The next Start Time needs to be equal or greater than the previous Finish Time.", , " ....." Range("F15").ClearContents Range("F15").Select End If If Range("I8") = "" Then Exit Sub If Range("I11") = "" Then Exit Sub If Range("I11").Value < Range("I8").Value And Range("I9").Value < Range("V17").Value Then MsgBox "There is an overlap in the Times Entered." & vbCrLf & "The next Start Time needs to be equal or greater than the previous Finish Time.", , "...." Range("I11").ClearContents Range("I11").Select End If If Range("I15") < "" And Range("I15") < Range("I12") And Range("I11").Value < Range("V17").Value Then MsgBox "There is an overlap in the Times Entered." & vbCrLf & "The next Start Time needs to be equal or greater than the previous Finish Time.", , "...." Range("I15").ClearContents Range("I15").Select End If If Range("L8") = "" Then Exit Sub If Range("L11") = "" Then Exit Sub If Range("L11").Value < Range("L8").Value And Range("Ll9").Value < Range("V17").Value Then MsgBox "There is an overlap in the Times Entered." & vbCrLf & "The next Start Time needs to be equal or greater than the previous Finish Time.", , "...." Range("L11").ClearContents Range("L11").Select End If If Range("L15") < "" And Range("L15") < Range("L12") And Range("L11").Value < Range("V17").Value Then MsgBox "There is an overlap in the Times Entered." & vbCrLf & "The next Start Time needs to be equal or greater than the previous Finish Time.", , "...." Range("L15").ClearContents Range("L15").Select End If If Range("O8") = "" Then Exit Sub If Range("O11") = "" Then Exit Sub If Range("O11").Value < Range("O8").Value And Range("O9").Value < Range("V17").Value Then MsgBox "There is an overlap in the Times Entered." & vbCrLf & "The next Start Time needs to be equal or greater than the previous Finish Time.", , " ....." Range("O11").ClearContents Range("O11").Select End If If Range("O15") < "" And Range("O15") < Range("O12") And Range("O11").Value < Range("V17").Value Then MsgBox "There is an overlap in the Times Entered." & vbCrLf & "The next Start Time needs to be equal or greater than the previous Finish Time.", , " ....." Range("O15").ClearContents Range("O15").Select End If If Range("R8") = "" Then Exit Sub If Range("R11") = "" Then Exit Sub If Range("R11").Value < Range("R8").Value And Range("R9").Value < Range("V17").Value Then MsgBox "There is an overlap in the Times Entered." & vbCrLf & "The next Start Time needs to be equal or greater than the previous Finish Time.", , " ....." Range("R11").ClearContents Range("R11").Select End If If Range("R15") < "" And Range("R15") < Range("R12") And Range("R11").Value < Range("V17").Value Then MsgBox "There is an overlap in the Times Entered." & vbCrLf & "The next Start Time needs to be equal or greater than the previous Finish Time.", , "" Range("R15").ClearContents Range("R15").Select End If If Range("U8") = "" Then Exit Sub If Range("U11") = "" Then Exit Sub If Range("U11").Value < Range("U8").Value And Range("U9").Value < Range("V17").Value Then MsgBox "There is an overlap in the Times Entered." & vbCrLf & "The next Start Time needs to be equal or greater than the previous Finish Time.", , " ....." Range("U11").ClearContents Range("U11").Select End If If Range("U15") < "" And Range("U15") < Range("U12") And Range("U11").Value < Range("V17").Value Then MsgBox "There is an overlap in the Times Entered." & vbCrLf & "The next Start Time needs to be equal or greater than the previous Finish Time.", , " ....." Range("U15").ClearContents Range("U15").Select End If End Sub COrey.... |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Can I simplify a VB code?????? | Excel Discussion (Misc queries) | |||
code to check file size everytime an Excel file is opened | Excel Programming | |||
Simplify this code | Excel Programming | |||
File Size Code not working | Excel Programming | |||
Help to simplify code. | Excel Programming |