daphnedaphy
New Member
- Joined
- Feb 17, 2014
- Messages
- 7
Hello Everyone,
I'm pretty new to VBA and hope you can advise me in some coding which I'm currently stuck for days.
I have 1 sheet (Sheet 2) which have a list of name, designation, department and hours. In another sheet (Sheet 2) I would like to run a summary of the total number hours in each department has. I'm using VBA nested loop to check if data exist in "Sheet 2". If it's exist it will calculated the number of hours in each department.
The issue i'm facing is, the loop only run once. I tried writing the pseudo code, the logic work but when I run it. The code run once.
Sheet 1 data
<tbody>
</tbody>
Sheet 2 data (output)
<tbody>
</tbody>
My Code as follow:
Can someone shine me some light?
Million Thanks!
I'm pretty new to VBA and hope you can advise me in some coding which I'm currently stuck for days.
I have 1 sheet (Sheet 2) which have a list of name, designation, department and hours. In another sheet (Sheet 2) I would like to run a summary of the total number hours in each department has. I'm using VBA nested loop to check if data exist in "Sheet 2". If it's exist it will calculated the number of hours in each department.
The issue i'm facing is, the loop only run once. I tried writing the pseudo code, the logic work but when I run it. The code run once.
Sheet 1 data
Name | Role | Department | Hours Spent |
AAA | Designer | Creative | 2 |
BBB | Developer | Development | 4 |
CCC | Senior Developer | Development | 6 |
DDD | Account Manager | Account | 8 |
EEE | Account Assistant | Account | 10 |
<tbody>
</tbody>
Sheet 2 data (output)
Department | Total Hours |
Account | 18 |
Creative | |
Development |
<tbody>
</tbody>
My Code as follow:
Code:
Sub CountResourceHours()
Dim rTimeHr, rDashboardTime As Range
Set rTimeHr = Worksheets("Sheet2").Range("C2")
Set rDashboardTime = Worksheets("Sheet3").Range("A2")
Do While rDashboardTime.Text <> ""
Do While rTimeHr.Text <> ""
If rTimeHr = rDashboardTime Then
rDashboardTime.Offset(columnoffset:=1) = rDashboardTime.Offset(columnoffset:=1) + rTimeHr.Offset(columnoffset:=1)
End If
Set rTimeHr = rTimeHr.Offset(rowoffset:=1)
Loop
Set rDashboardTime = rDashboardTime.Offset(rowoffset:=1)
Loop
End Sub
Can someone shine me some light?
Million Thanks!