You may try this worksheet change event code to get the desired output.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim ws As Worksheet
Dim rng As Range
Dim lr As Long, r As Long
If Target.Count > 1 Then Exit Sub
If Not Intersect(Target, Range("H6")) Is Nothing Then
With Range("I14:I19")
.Interior.ColorIndex = 6
.ClearContents
End With
Application.EnableEvents = False
If Target.Offset(3, 0) <> "Enter Employee Name" Then
For Each ws In Worksheets
If ws.Name <> "Summary" And WorksheetFunction.Text(ws.Range("Af2").Value, "mmmm") = Target Then
On Error Resume Next
r = WorksheetFunction.Match(Target.Offset(3, 0), ws.Range("B:B"), 0)
On Error GoTo 0
If r > 0 Then
Range("I14").Value = ws.Cells(r, "AJ")
Range("I15").Value = ws.Cells(r, "AK")
Range("I16").Value = ws.Cells(r, "AL")
Range("I17").Value = ws.Cells(r, "AM")
Range("I18").Value = ws.Cells(r, "AN")
Range("I19").Value = ws.Cells(r, "AO")
Application.EnableEvents = True
Exit Sub
Else
MsgBox "Employee not found for this month"
Application.EnableEvents = True
Exit Sub
End If
End If
Next ws
End If
End If
If Not Intersect(Target, Range("H9")) Is Nothing Then
With Range("I14:I19")
.Interior.ColorIndex = 6
.ClearContents
End With
Application.EnableEvents = False
If Target.Offset(-3, 0) <> "Enter Month" Then
For Each ws In Worksheets
If ws.Name <> "Summary" And WorksheetFunction.Text(ws.Range("Af2").Value, "mmmm") = Target.Offset(-3, 0) Then
On Error Resume Next
r = WorksheetFunction.Match(Target, ws.Range("B:B"), 0)
On Error GoTo 0
If r > 0 Then
Range("I14").Value = ws.Cells(r, "AJ")
Range("I15").Value = ws.Cells(r, "AK")
Range("I16").Value = ws.Cells(r, "AL")
Range("I17").Value = ws.Cells(r, "AM")
Range("I18").Value = ws.Cells(r, "AN")
Range("I19").Value = ws.Cells(r, "AO")
Application.EnableEvents = True
Exit Sub
Else
MsgBox "Employee not found for this month"
Application.EnableEvents = True
Exit Sub
End If
End If
Next ws
End If
End If
Application.EnableEvents = True
End Sub
Please find the attached sheet and just change either the Month or Employee to get the desired output in the yellow cells.
Is this what you are trying to achieve?
Bookmarks