PDA

View Full Version : VBA code for attendance template - In time & Out Time



vmjamshad
11-09-2017, 05:10 AM
Hi, I am trying create attendance template using VBA. I managed to create one. But if I have a IN & OUT time on different dates (Example - In on 9/11/2017 8 PM and OUT on 10/11/2017 8 AM) i am not able to get it proper. Here I want a code to work on both (IN & OUT on the same day and IN & OUT on different dates). Please see the attendance data below:



Date & Time
Transaction Type


03/01/2016 8:38
I


03/01/2016 18:36
O


04/01/2016 8:12
I


04/01/2016 17:23
O


06/01/2016 8:14
I


06/01/2016 19:17
O


07/01/2016 20:00
I


08/01/2016 10:02
O


10/01/2016 8:22
I


11/01/2016 19:51
O


13/01/2016 8:22
I


13/01/2016 19:51
O

Paul_Hossler
11-09-2017, 08:03 AM
You didn't say what you wanted to end result to look like. Attaching a sample workbook with a Before and After and enough data to show the issue really helps

This assume that the data is 'nice' and take the input sheet with data like your post, and puts it on another sheet

You're have to massage it to fit your template



Option Explicit
Sub test()
Dim i As Long, o As Long

o = 2
With Worksheets("Sheet1")
For i = 2 To .Cells(1, 1).CurrentRegion.Rows.Count Step 2
Worksheets("Sheet2").Cells(o, 1).Value = .Cells(i, 1).Value
Worksheets("Sheet2").Cells(o, 2).Value = .Cells(i + 1, 1).Value
o = o + 1
Next I
End With
End Sub

vmjamshad
11-09-2017, 10:23 AM
Thank for your reply. I am attaching the template and the code which i used in that sheet.