Help with collections and types.

manonfire32

New Member
Joined
Jun 14, 2012
Messages
2
Hi everyone,

I am trying to use a collection and type to gather data from 2 sheets and output it on the third sheet. I believe I have some syntax errors and any help fixing them would be appreciated. The following is my code:


Type Person


name As String
eeid As String
ot As Single
reg As Single


End Type




Public Sub Readdatafile()






Dim row As Integer
Dim p As Person
Dim ptemp As Person
Dim company As Collection


Dim comp() As Person








For row = 1 To 50
If Cells(row, 1) = "TOTALS" Then


'if row is timecard/total
'read row and set values

p.eeid = Cells(row, 3).Value
p.name = Cells(row, 2).Value
p.reg = Cells(row, 5).Value
p.ot = Cells(row, 6).Value

'check if person is already in the collection
found = False
Index = 0
For Index = 1 To company.Count
Set ptemp = company(Item)
If ptemp.name = p.name Then
found = True
Index = Item
break
End If
Next row

If found Then
'increment the person's reg and ot time.
Set ptemp = company(Index)
ptemp = ptemp.reg + p.reg
Else 'person is not in the collection, add person
company.Add p
End If
Next


'now data is filled


'fill in headers here
Cells(1, 1).Value = "EEID"
Cells(1, 2).Value = "DET"
Cells(1, 3).Value = "DET CODE"
Cells(1, 4).Value = "HOURS"


row = 2
For Item = 1 To company.Count
Set ptemp = company(Item)

Sheet3.Cells(row, 1).Value = ptemp.eeid
Sheet3.Cells(row, 2).Value = "E"
Sheet3.Cells(row, 3).Value = "REG"
Sheet3.Cells(row, 4).Value = ptemp.reg
row = row + 1

If (company(Item).ot > 0) Then
Sheet3.Cells(row, 1).Value = ptemp.eeid
Sheet3.Cells(row, 2).Value = "E"
Sheet3.Cells(row, 3).Value = "OT"
Sheet3.Cells(row, 4).Value = ptemp.ot
row = row + 1
End If


End Sub
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

Forum statistics

Threads
1,214,834
Messages
6,121,873
Members
449,056
Latest member
ruhulaminappu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top