I have a button that calls 'CopyMatchingValues'.
The 'CopyMatchingValues' event then requires me to select the range of values in column C that I want to process using an input box.
If the OvertimeCell.Value that matches the OTFormRange.Value from the selection, exceeds more than 11 matching values,
I want the Sub to Exit, the input box to close and the event to call 'CopyMatchingXValues'
Can you please show me how to do this.


Sub CopyMatchingValues()
    Dim OvertimeSheet As Worksheet
    Dim OTFormSheet As Worksheet
    Dim OvertimeRange As Range
    Dim OTFormRange As Range
    Dim OvertimeCell As Range
    Dim OTFormCell As Range
    Dim LastRow As Long
    Dim i As Long
    Set OvertimeSheet = ThisWorkbook.Sheets("Overtime")
    On Error Resume Next
    Set OvertimeRange = Application.InputBox("Select range in column C", Type:=8)
    On Error GoTo 0
    If OvertimeRange Is Nothing Or Not OvertimeRange.Columns(1).Column = 3 Then
        MsgBox "No valid range selected in column C.", vbCritical
        Exit Sub
    End If
    Set OTFormSheet = ThisWorkbook.Sheets("OTForm")
    Set OTFormRange = OTFormSheet.Range("B4")
    LastRow = 11
    For Each OvertimeCell In OvertimeRange
        If OvertimeCell.Value = OTFormRange.Value Then
        OTFormSheet.Cells(LastRow, "D").Value = OvertimeCell.Offset(0, 28).Value
        OTFormSheet.Cells(LastRow, "C").Value = OvertimeCell.Offset(0, 27).Value
        OTFormSheet.Cells(LastRow, "B").Value = OvertimeCell.Offset(0, 1).Value
        OTFormSheet.Cells(LastRow, "A").Value = OvertimeCell.Offset(0, -2).Value
            LastRow = LastRow + 1
        End If
    Next OvertimeCell
    OTFormSheet.Range("I24").Value = Date
    OTFormSheet.Range("I25").Value = Date
    Dim message As String
message = OTFormSheet.Range("B4").Value & "'s overtime dates have been entered"
MsgBox message, vbInformation, "OVERTIME ENTRY"
ThisWorkbook.Sheets("OTForm").Activate
End Sub

Sub CopyMatchingXValues()
MsgBox "Values found exceed space allocated for standard sheet, please use Extended Overtime Sheet"
    Dim OvertimeSheet As Worksheet
    Dim OTFormXSheet As Worksheet
    Dim OvertimeRange As Range
    Dim OTFormXRange As Range
    Dim OvertimeCell As Range
    Dim OTFormXCell As Range
    Dim LastRow As Long
    Dim i As Long
    Set OvertimeSheet = ThisWorkbook.Sheets("Overtime")
    On Error Resume Next
    Set OvertimeRange = Application.InputBox("Select range in column C", Type:=8)
    On Error GoTo 0
    If OvertimeRange Is Nothing Or Not OvertimeRange.Columns(1).Column = 3 Then
        MsgBox "No valid range selected in column C.", vbCritical
        Exit Sub
    End If
    Set OTFormXSheet = ThisWorkbook.Sheets("OTFormX")
    Set OTFormXRange = OTFormXSheet.Range("B4")
    LastRow = 11
    For Each OvertimeCell In OvertimeRange
        If OvertimeCell.Value = OTFormXRange.Value Then
        OTFormXSheet.Cells(LastRow, "D").Value = OvertimeCell.Offset(0, 28).Value
        OTFormXSheet.Cells(LastRow, "C").Value = OvertimeCell.Offset(0, 27).Value
        OTFormXSheet.Cells(LastRow, "B").Value = OvertimeCell.Offset(0, 1).Value
        OTFormXSheet.Cells(LastRow, "A").Value = OvertimeCell.Offset(0, -2).Value
            LastRow = LastRow + 1
        End If
    Next OvertimeCell
    OTFormXSheet.Range("I45").Value = Date
    OTFormXSheet.Range("I46").Value = Date
    Dim message As String
message = OTFormXSheet.Range("B4").Value & "'s overtime dates have been entered"
MsgBox message, vbInformation, "OVERTIME ENTRY"
ThisWorkbook.Sheets("OTFormX").Activate
End Sub