Hi,
I can usually make my VBA code work but I just can't seem to get the sum function to work properly.
I have a sheet for every person in my small business (8 people), each sheet is named after the employee. Their time gets entered into their sheets every day (so I have the date, time in, time out, and total hours (column I))
On Sheet 2 I want to be able to enter a start date (A2) and an end date (B2). I then want a VBA to search each employees sheet and sum the hours between these two dates and show me this sum on sheet2 on a specified cell
On sheet 2 I have every employee listed from A7 till A15.
for example if I enter 8-03-19 into Sheet2 A2 and 14-03-19 into sheet 2 A3, the VBA should be able to look at Sheet2 A7 (lets say that says john) then look in the sheet named john sum the total hours (column I) from 8-03-19 to 14-03-19.
I can mage to use a for loop to search johns sheet and find the row that has 8-03-14 but then getting it to sum the rows I cant manage.
Here's my code thus far:
Sub Hours()
Dim i As Integer
For i = 2 To 32
a = Worksheets("Sheet2").Range("A7") Here "a" becomes John
If Worksheets(a).Cells(i, 2).Value = Worksheets("Sheet2").Range("A2").Value Then Here im comparing sheet John's column B until i find the date thats in Sheet2 A2
Worksheets("Sheet2").Range("B7") = Worksheets(a).Cells(i, 9).Value + Worksheets(a).Cells(i + 1, 9).Value + Worksheets(a).Cells(i + 2, 9).Value + Worksheets(a).Cells(i + 3, 9).Value + Worksheets(a).Cells(i + 4, 9).Value + Worksheets(a).Cells(i + 5, 9).Value + Worksheets(a).Cells(i + 6, 9).Value This is a very crude way of summing johns column I from the start date in Sheet2 A2 for 7 days
End If
Next i
End Sub
Im trying to explain this as best as I can, if you need an explanation just ask. PS once I figure it out for one employee I can just repeat the code for every employee. At least thats what I wouldve done, unless theres a better way.
Thanks!!
I can usually make my VBA code work but I just can't seem to get the sum function to work properly.
I have a sheet for every person in my small business (8 people), each sheet is named after the employee. Their time gets entered into their sheets every day (so I have the date, time in, time out, and total hours (column I))
On Sheet 2 I want to be able to enter a start date (A2) and an end date (B2). I then want a VBA to search each employees sheet and sum the hours between these two dates and show me this sum on sheet2 on a specified cell
On sheet 2 I have every employee listed from A7 till A15.
for example if I enter 8-03-19 into Sheet2 A2 and 14-03-19 into sheet 2 A3, the VBA should be able to look at Sheet2 A7 (lets say that says john) then look in the sheet named john sum the total hours (column I) from 8-03-19 to 14-03-19.
I can mage to use a for loop to search johns sheet and find the row that has 8-03-14 but then getting it to sum the rows I cant manage.
Here's my code thus far:
Sub Hours()
Dim i As Integer
For i = 2 To 32
a = Worksheets("Sheet2").Range("A7") Here "a" becomes John
If Worksheets(a).Cells(i, 2).Value = Worksheets("Sheet2").Range("A2").Value Then Here im comparing sheet John's column B until i find the date thats in Sheet2 A2
Worksheets("Sheet2").Range("B7") = Worksheets(a).Cells(i, 9).Value + Worksheets(a).Cells(i + 1, 9).Value + Worksheets(a).Cells(i + 2, 9).Value + Worksheets(a).Cells(i + 3, 9).Value + Worksheets(a).Cells(i + 4, 9).Value + Worksheets(a).Cells(i + 5, 9).Value + Worksheets(a).Cells(i + 6, 9).Value This is a very crude way of summing johns column I from the start date in Sheet2 A2 for 7 days
End If
Next i
End Sub
Im trying to explain this as best as I can, if you need an explanation just ask. PS once I figure it out for one employee I can just repeat the code for every employee. At least thats what I wouldve done, unless theres a better way.
Thanks!!