Scanning schedule

shekhar_pc

Board Regular
Joined
Jan 29, 2006
Messages
185
try.xls
ABCDEFGHIJ
1EmployeeEmp ID2-Dec3-Dec4-Dec5-Dec6-Dec7-Dec8-Dec9-Dec
2A123409:00 PM - 06:00 AM09:00 PM - 06:00 AM09:00 PM - 06:00 AM09:00 PM - 06:00 AM09:00 PM - 06:00 AM
3B123511:30 PM - 08:30 AM11:30 PM - 08:30 AM11:30 PM - 08:30 AM11:30 PM - 08:30 AM11:30 PM - 08:30 AM
4C123602:30 AM - 11:30 AMCasual Leave02:30 AM - 11:30 AM02:30 AM - 11:30 AM02:30 AM - 11:30 AM
5D123705:30 AM - 03:00 PM05:30 AM - 03:00 PM05:30 AM - 03:00 PM05:30 AM - 03:00 PM05:30 AM - 03:00 PM
6E123811:30 PM - 08:30 AM11:30 PM - 08:30 AM11:30 PM - 08:30 AM11:30 PM - 08:30 AM11:30 PM - 08:30 AM
7F123905:30 AM - 03:00 PMSick Leave05:30 AM - 03:00 PM05:30 AM - 03:00 PM05:30 AM - 03:00 PM
8G124009:00 PM - 06:00 AM09:00 PM - 06:00 AM09:00 PM - 06:00 AM09:00 PM - 06:00 AM09:00 PM - 06:00 AM
9H124102:30 AM - 11:30 AM02:30 AM - 11:30 AM02:30 AM - 11:30 AM02:30 AM - 11:30 AM02:30 AM - 11:30 AM
Sheet1


Hi!

I have posted this question earlier but did not get any help. I have tried a lot but I am unable to achieve what I need.

The table posted above is the schedule for my employee. I need an input box which asks for a date. When the user supplies date, it should look for people who are scheduled for that particular date and who are on leave and put the result in the next worksheet at the last occupied row.

For instance, if I supply the date as 2nd Dec then the next worksheet should be filled with @ row # 2 (Row1 has headings)
Employee Emp ID Schedule
A 1234 09:00 PM - 06:00 AM
B 1235 11:30 PM - 08:30 AM
C 1236 02:30 AM - 11:30 AM
E 1238 11:30 PM - 08:30 AM
G 1240 09:00 PM - 06:00 AM

Then if I select 3rd Dec, the next worksheet should be filled with the following data starting fom row number 7 (just below the above data)
A 1234 09:00 PM - 06:00 AM
B 1235 11:30 PM - 08:30 AM
D 1237 05:30 AM - 03:00 PM
G 1240 09:00 PM - 06:00 AM
 
Still not working the way I want. Lets say if I change the schedule for 7-Dec to the below and keep 8th Dec schedule as it is as per my first post.

Employee Emp ID 7-Dec
A 1234 09:00 PM - 06:00 AM
B 1235 Sick Leave
C 1236 02:30 AM - 11:30 AM
D 1237 05:30 AM - 03:00 PM
E 1238 11:30 PM - 08:30 AM
F 1239 05:30 AM - 03:00 PM
G 1240
H 1241 02:30 AM - 11:30 AM

The extracted schedule should be:

A 1234 09:00 PM - 06:00 AM
B 1235 Sick Leave
D 1237 Casual Leave
E 1238 11:30 PM - 08:30 AM
F 1239 05:30 AM - 03:00 PM
H 1241 02:30 AM - 11:30 AM

whereas after editing the line and running your code, I am not getting schedule for "F" and "H"???

"F" is working in 5:30 AM shift on 8th so ideally it is a shift for 7th and should be extracted.
similarly, "H" is working in 2:30 AM shift on 8th so ideally it is a shift for 7th and should be extracted.
 
Upvote 0

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
OK. See if this helps you.

Code:
Sub SchedScan_v02()
Dim ws1     As Worksheet, ws2   As Worksheet
Dim lRow    As Long, DtCol      As Byte
Dim SchdDt  As String, SchCell  As Range
Dim Rng     As Range, SchdTime  As String
Dim Dest    As Range, x

Set ws1 = Sheets("Sheet1"): Set ws2 = Sheets("Sheet2")
lRow = ws1.Range("A" & Rows.Count).End(xlUp).Row
Set Dest = ws2.Range("A" & Rows.Count).End(xlUp).Offset(1)
SchdDt = Application.InputBox("Enter Date", "Schedule Date", "m/d/yyyy")
    Application.ScreenUpdating = False
    If SchdDt = vbNullString Then
        Exit Sub
    End If
    SchdDt = Format(SchdDt, "d-mmm")
    If Application.WorksheetFunction.CountIf(ws1.Rows(1), SchdDt) > 0 Then
    DtCol = ws1.Rows(1).Find(What:=SchdDt, LookIn:=xlValues).Column
        Set Rng = ws1.Range(ws1.Cells(2, DtCol), ws1.Cells(lRow, DtCol))
            For Each SchCell In Rng
                If Not IsEmpty(SchCell) Then
                    x = Split(SchCell.Value, "-")
                    SchdTime = x(0)
                    If InStr(1, SchdTime, "PM") > 0 Or _
                            InStr(1, SchCell.Value, "Leave") > 0 Then
                        Dest = ws1.Cells(SchCell.Row, 1)
                        Dest.Offset(, 1) = ws1.Cells(SchCell.Row, 2)
                        Dest.Offset(, 2) = SchCell
                        Set Dest = Dest.Offset(1)
                    Else
                        If InStr(1, SchdTime, "AM") > 0 Then
                            If Not IsEmpty(SchCell.Offset(, 1)) Then
                                x = Split(SchCell.Offset(, 1).Value, "-")
                                SchdTime = x(0)
                                If InStr(1, SchCell.Offset(, 1), "Leave") > 0 Or _
                                    InStr(1, SchdTime, "AM") > 0 Then
                                    Dest = ws1.Cells(SchCell.Row, 1)
                                    Dest.Offset(, 1) = ws1.Cells(SchCell.Row, 2)
                                    Dest.Offset(, 2) = SchCell.Offset(, 1)
                                    Set Dest = Dest.Offset(1)
                                End If
                            End If
                        End If
                    End If
                Else
                    If Not IsEmpty(SchCell.Offset(, 1)) Then
                        x = Split(SchCell.Offset(, 1).Value, "-")
                        SchdTime = x(0)
                            If InStr(1, SchdTime, "AM") > 0 Then
                                Dest = ws1.Cells(SchCell.Row, 1)
                                Dest.Offset(, 1) = ws1.Cells(SchCell.Row, 2)
                                Dest.Offset(, 2) = SchCell.Offset(, 1)
                                Set Dest = Dest.Offset(1)
                            Else
                                GoTo Again
                            End If
                    Else
                        GoTo Again
                    End If
                End If
Again:
            Next SchCell
    Else
        MsgBox "Date: '" & SchdDt & "' Not Found!"
    End If
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Yet it did.

Ultimate solution. Greatly appreciated...... Thank you very much for looking into my problem. I have been running around with this for quite some days. Inspite of my unclear explanation, you've understood the entire scenario. Thanks again.

Cheers !
 
Upvote 0
Yet it did.

Ultimate solution. Greatly appreciated...... Thank you very much for looking into my problem. I have been running around with this for quite some days. Inspite of my unclear explanation, you've understood the entire scenario. Thanks again.

Cheers !

You are welcome :beerchug:
 
Upvote 0

Forum statistics

Threads
1,223,840
Messages
6,174,953
Members
452,593
Latest member
Jason5710

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top