karangambhir
New Member
- Joined
- Jul 25, 2017
- Messages
- 1
I have a code which I need to run on all the sheets in a Workbook except "All Employee" Sheet.
This code calculates the time spent by the employees in a shift and their less time (Time not completed in a shift) for each day of the month which is logged horizontally in the sheet.
The problem I am facing is that it shows the correct values on all the sheets except the one which is open when I run the macro.
Here Cell (2,69) contains the value of the number of hours which is supposed to be completed in a shift.
---------------------------------------------------------------------------------------------------------------------------------------------
Public Sub timing()Dim w As Integer, x As Integer, y As Integer, z As Integer, slr As Integer, WS_Count As Integer, S As Integer, lcol As Long
WS_Count = ActiveWorkbook.Worksheets.Count
For S = 2 To WS_Count
If Sheets(S).Name <> "All Employee" Then Sheets(S).Select Replace:=False
slr = Sheets(S).Range("A" & Rows.Count).End(xlUp).Row + 1
lcol = Sheets(S).Cells(1, Columns.Count).End(xlToLeft).Column + 1
For x = 4 To slr Step 2
Sheets(S).Cells(x, "F").FormulaR1C1 = "=R[-1]C[1]-R[-1]C"
Range("F" & x & ":G" & x).Select
Selection.AutoFill Destination:=Range("F" & x & ":BO" & x), Type:=xlFillDefault
Next x
Next S
For S = 2 To WS_Count
If Sheets(S).Name <> "All Employee" Then Sheets(S).Select Replace:=False
slr = Sheets(S).Range("A" & Rows.Count).End(xlUp).Row + 1
lcol = Sheets(S).Cells(1, Columns.Count).End(xlToLeft).Column + 1
For z = 4 To slr Step 2
For y = 7 To lcol Step 2
w = y - 1
If Sheets(S).Cells(2, 69).Value2 > Sheets(S).Cells(z, w).Value2 Then
Sheets(S).Cells(z, y) = Sheets(S).Cells(2, 69).Value2 - Sheets(S).Cells(z, w).Value2
Sheets(S).Cells(z, y).Font.ColorIndex = 3
Else
Sheets(S).Cells(z, y) = Sheets(S).Cells(z, w).Value2 - Sheets(S).Cells(2, 69).Value2
Sheets(S).Cells(z, y).Font.ColorIndex = 10
End If
Next y
Next z
Next S
End Sub
This code calculates the time spent by the employees in a shift and their less time (Time not completed in a shift) for each day of the month which is logged horizontally in the sheet.
The problem I am facing is that it shows the correct values on all the sheets except the one which is open when I run the macro.
Here Cell (2,69) contains the value of the number of hours which is supposed to be completed in a shift.
---------------------------------------------------------------------------------------------------------------------------------------------
Public Sub timing()Dim w As Integer, x As Integer, y As Integer, z As Integer, slr As Integer, WS_Count As Integer, S As Integer, lcol As Long
WS_Count = ActiveWorkbook.Worksheets.Count
For S = 2 To WS_Count
If Sheets(S).Name <> "All Employee" Then Sheets(S).Select Replace:=False
slr = Sheets(S).Range("A" & Rows.Count).End(xlUp).Row + 1
lcol = Sheets(S).Cells(1, Columns.Count).End(xlToLeft).Column + 1
For x = 4 To slr Step 2
Sheets(S).Cells(x, "F").FormulaR1C1 = "=R[-1]C[1]-R[-1]C"
Range("F" & x & ":G" & x).Select
Selection.AutoFill Destination:=Range("F" & x & ":BO" & x), Type:=xlFillDefault
Next x
Next S
For S = 2 To WS_Count
If Sheets(S).Name <> "All Employee" Then Sheets(S).Select Replace:=False
slr = Sheets(S).Range("A" & Rows.Count).End(xlUp).Row + 1
lcol = Sheets(S).Cells(1, Columns.Count).End(xlToLeft).Column + 1
For z = 4 To slr Step 2
For y = 7 To lcol Step 2
w = y - 1
If Sheets(S).Cells(2, 69).Value2 > Sheets(S).Cells(z, w).Value2 Then
Sheets(S).Cells(z, y) = Sheets(S).Cells(2, 69).Value2 - Sheets(S).Cells(z, w).Value2
Sheets(S).Cells(z, y).Font.ColorIndex = 3
Else
Sheets(S).Cells(z, y) = Sheets(S).Cells(z, w).Value2 - Sheets(S).Cells(2, 69).Value2
Sheets(S).Cells(z, y).Font.ColorIndex = 10
End If
Next y
Next z
Next S
End Sub