elefantsko
New Member
- Joined
- Feb 18, 2015
- Messages
- 3
Hi everyone! I have a small problem and I really can't figure out how to solve it.
I have a sheet called "TIDRAPPORT" where i have lots of rows with lots of info. You can say it's a "time report excel document" for a company. What I want to do is calculate the amount of time each person has worked in a specific project. I'll post a picture of one of the rows:
Column C is the Order nr that the user write in a textbox and clicks "go". What my program should do then is go through all rows and collect the workers (column I, "Vem") and the time they work (Kolumn J, "Tid"). If the name occurs twice or more the program will then add the ours to the person with the same name.
I have managed to write the code (which I also got help with) to collect the hours workers worked, but in ALL PROJECTS (there are alot).. I'm having trouble with writing the code so it checks that the input is the same as the content in column C before it adds the information to the array.. Can somebody help?
Ps. I'm sorry but I don't know how to write the code in "code mode".. But here's what i got so far:
Sub getWorkers()
Dim s As String
s = Worksheets("PROGRAM").TextBox1.Text
Dim Dic As Object, oCell As Range, i&, y%, key As Variant
Set Dic = CreateObject("Scripting.Dictionary")
y = 1: i = ThisWorkbook.Sheets("TIDRAPPORT").Cells(Rows.Count, 9).End(xlUp).Row
For Each oCell In Range("I26:I" & i)
If Not Dic.exists(oCell.Value) Then
Dic.Add oCell.Value, WorksheetFunction.SumIf(Range("I26:I" & i), oCell.Value, Range("J26:J" & i))
End If
Next
For Each key In Dic
Debug.Print key, Dic(key)
Next
End Sub
I have a sheet called "TIDRAPPORT" where i have lots of rows with lots of info. You can say it's a "time report excel document" for a company. What I want to do is calculate the amount of time each person has worked in a specific project. I'll post a picture of one of the rows:

Column C is the Order nr that the user write in a textbox and clicks "go". What my program should do then is go through all rows and collect the workers (column I, "Vem") and the time they work (Kolumn J, "Tid"). If the name occurs twice or more the program will then add the ours to the person with the same name.
I have managed to write the code (which I also got help with) to collect the hours workers worked, but in ALL PROJECTS (there are alot).. I'm having trouble with writing the code so it checks that the input is the same as the content in column C before it adds the information to the array.. Can somebody help?
Ps. I'm sorry but I don't know how to write the code in "code mode".. But here's what i got so far:
Sub getWorkers()
Dim s As String
s = Worksheets("PROGRAM").TextBox1.Text
Dim Dic As Object, oCell As Range, i&, y%, key As Variant
Set Dic = CreateObject("Scripting.Dictionary")
y = 1: i = ThisWorkbook.Sheets("TIDRAPPORT").Cells(Rows.Count, 9).End(xlUp).Row
For Each oCell In Range("I26:I" & i)
If Not Dic.exists(oCell.Value) Then
Dic.Add oCell.Value, WorksheetFunction.SumIf(Range("I26:I" & i), oCell.Value, Range("J26:J" & i))
End If
Next
For Each key In Dic
Debug.Print key, Dic(key)
Next
End Sub