samedi 13 juin 2020

If Row condition satisfy then check with column wise

There are 3 Sheets-

1-Requested_Role - 2-Training_For_Specific_Role 3-Completed_Training

Requested_Role Sheet contains 3 Columns - User ID, Requested Role, Status

Training_For_Specific_Role contains 3 Columns - Requested Role, Training_1, Training_2

Completed_Training contains 2 Columns - User ID, Training Completed

To get the requested role user needs to complete certain training's. Sometimes one training is enough to get the role and sometimes user needs to completed both training like Or condition and " AND" condition.

Assume-

There are three user id in the Requested Role Sheet -

User ID   Requested Role  Status
USER_1,   TC
USER_2,   TSC
USER_3    DC

enter image description here

In Training_For_Specific_Role Sheet

Requested Role      Training_1           Training_1           
TC                  ABC
TSC                 JFR                   BGF
DC                  MNP                   OPD

enter image description here

For TSC role either Training_1 or Training_2 any role is completed , User will get access For DC role Both the Training_1 and Training_2 both the Training needs to be completed.

If USER is match the above criteria then in Requested Role Sheet under status column will be updated with Accepted , if Criteria not matched then Status will be updated with Rejected

Code I have written but that is not the full one . If user is requested for a role which needs one one training then below code is working perfectly but AND or condition is not mentioned.

Sub check_Status_New() Dim rrow As Long Dim trow As Long Dim crow As Long

Dim i As Long
Dim j As Long
Dim k As Long

Dim UserID As String
Dim RequestedRole As String
Dim Training As String

Dim Found As Boolean

rrow = Worksheets("Requested_Role").Cells(Rows.Count, 1).End(xlUp).Row
trow = Worksheets("Training_For_Specific_Role").Cells(Rows.Count, 1).End(xlUp).Row
crow = Worksheets("Completed_Training").Cells(Rows.Count, 1).End(xlUp).Row

For i = 2 To rrow
    UserID = Worksheets("Requested_Role").Cells(i, 2)
    RequestedRole = Worksheets("Requested_Role").Cells(i, 3)
    Training = ""
    Found = False
    For j = 2 To trow
        If Worksheets("Training_For_Specific_Role").Cells(j, 1) = RequestedRole Then
            Training = Worksheets("Training_For_Specific_Role").Cells(j, 2)
            Exit For
        End If
    Next j
    If Training = "" Then
        Worksheets("Requested_Role").Cells(i, 5) = "Training For Specific Role not found"
    Else
        For k = 2 To crow
            If Worksheets("Completed_Training").Cells(k, 1) = UserID Then
                If Worksheets("Completed_Training").Cells(k, 2) = Training Then
                    Found = True
                    Exit For
                End If
            End If
        Next k
        If Found = True Then
            Worksheets("Requested_Role").Cells(i, 5) = "Accept"
        Else
            Worksheets("Requested_Role").Cells(i, 5) = "Reject"
            Worksheets("Requested_Role").Cells(i, 6).Value = Training
            Worksheets("Requested_Role").Cells(i, 5).Interior.Color = vbGreen

        End If
    End If
Next i

Worksheets("Requested_Role").Activate
End Sub

Aucun commentaire:

Enregistrer un commentaire