Question : Error message based on validation rule - VB event handler

Hello, building on a previous response with this question.  I have attached a file for reference.

I have set a data validation popup to warn users they are creating a conflct with miles already assigned to someone else.  This will be a territory tracking spreadsheet and will happen, so that is why I am warning the users and not stopping them.

I am lookign for a way to populate the popup with the details of the conflict?  For example, have the popup tell the user something similar to  "The mile range you entered conflicts with Me's existing territory on I-35.  If this is what you intend to do, please adjust Me's territory on I-35 accordingly"

Thanks to Harfang and their work on this previously, they told me "I'm quite sure I don't know the best method to find all rows that overlap in VB, so I would suggest you ask a new related question (using the appropriate link in this question). The criteria to use is:

    Road = R And BegMile < E And EndMile > B

    R: current row's Road
    E: current row's End Mile
    B: current row's Beginning Mile"

My familiarity with VBA in excel is limitied to macros I have copied off the web... I've never written one myself.

Any ideas if this can be done?

Thank you!


 
 
 
 
 

Answer : Error message based on validation rule - VB event handler

Sorry Savants, I was a littlem sloppy,  here is a revised version.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
Public Sub CheckRoad(iRow As Integer)
    Dim lLastRow As Long
    
    LastRow& = Cells(Rows.Count, 3).End(xlUp).Row
    sRoad = Cells(iRow, 2).Value
    Start = Cells(iRow, 3).Value
    Finish = Cells(iRow, 4).Value
    bWarning = False
    
    For iX = 2 To LastRow
        If iX <> iRow Then
            If Cells(iX, 2).Value = sRoad Then
                If Cells(iX, 3).Value >= Start And Cells(iX, 3).Value <= Finish Then
                    sName = Cells(iX, 1).Value
                    bWarning = True
                End If
                If Cells(iX, 4).Value >= Start And Cells(iX, 4).Value <= Finish Then
                    sName = Cells(iX, 1).Value
                    bWarning = True
                End If
            End If
        End If
    Next iX
    
    sMessage = "The mile range you entered conflicts with" & sName
    sMessage = sMessage & "'s existing territory on I-35.  If this "
    sMessage = sMessage & "is what you intend to do, please adjust "
    sMessage = sMessage & sName & "'s territory on "
    sMessage = sMessage & sRoad & " accordingly"
    
    If bWarning Then
        Call MsgBox(sMessage, vbInformation)
    End If
Random Solutions  
 
programming4us programming4us