I have an application built where a dialogue box pops up, asks about two values in two columns in Sheet 2. If they both match, a msg box pops up, and then other instances other msgs. When I type in a job code, it matches to that job code, but that code could have multiple cost-centers aligned. My code is stopping at the first row where that match happens, but doesn't loop through all rows to see if it can find the cost-center. It returns a "found but not eligible for this cost-center" message, but it doesn't finish looping to truly be able to tell or not.
What do I need to change here to make sure it doesn't prematurely trigger that msg?
It's saying rFound
is finding the job code, but that job code has 4 rows for each eligible cost center spanning rows 211-14. It stops at row 211, then doesn't try looking through the other 3 rows where rFound is matched.
Code:
Option Explicit
Sub tgr()
Dim rFound As Range
Dim lJobCode As String
Dim lFLSA As String
Dim lCC As String
Dim sFirst As String
Dim sResults As String
Dim sh As Worksheet
Dim matched As Boolean
Dim Y As Integer, Z As Integer
lJobCode = Application.InputBox("Please provide a job code", "Job Code", Type:=2)
lCC = Application.InputBox("Please enter in a cost-center", "CC", Type:=2)
If lJobCode = "False" Or lCC = "False" Then Exit Sub 'Pressed cancel
Set sh = Sheets("Sheet1")
With ThisWorkbook.Worksheets("Sheet2").Columns("A")
Set rFound = .Find(lJobCode, .Cells(.Cells.Count), xlValues, xlWhole)
If Not rFound Is Nothing Then
If ThisWorkbook.Worksheets("Sheet2").Cells(rFound.Row, 3).Value = lCC Then
matched = True
If rFound.Offset(, 4).Value = "Exempt" And Y = 0 Then
MsgBox "Exempt roles may be eligible for schedule pay allowance."
Y = 1
Exit Sub 'if criteria is met, display above msgbox and then exit sub after user clicks ok or cancel
End If
If rFound.Offset(, 5).Value = "Eligible - Employee Level" And Z = 0 Then
MsgBox "This job is only eligible at the employee level."
Z = 1
Exit Sub
End If
MsgBox "Job Code (" & lJobCode & ") is eligible for this cost-center."
End If
If Not matched Then MsgBox "Job Code (" & lJobCode & ") found, but not eligible for this cost-center."
Else
MsgBox "Job Code (" & lJobCode & ") not eligible."
End If
End With
End Sub