Adding contents of cells for duplicates

excel_noob86

New Member
Joined
Nov 10, 2009
Messages
30
Hi,

I have an employee sheet which has multiple hours rows for one employee, i want to select an employee ID and add corresponding hours and place both in a separate sheet. Here's my code so far.
Code:
Sub dup()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Set NewSheet = Worksheets.Add
NewSheet.Name = "NEW"
Set NewSheet = Worksheets.Add
supcount = 2
     countresources = 0
     Do While Sheets("RS Nov 2009").Range("A" & supcount).Value <> ""
        countresources = countresources + 1
        supcount = supcount + 1
Loop
'Dim temp As Range
Dim i, j, hours As Integer
hours = 0
Sheets("RS Nov 2009").Select
     Columns("A:A").Select
     Selection.Copy
     Columns("Q:Q").Select
     Selection.Copy
For i = 0 To supcount
For j = i + 1 To supcount
If Sheets("RS Nov 2009").Range("A" & i).Value = Sheets("RS Nov 2009").Range("A" & j).Value Then
hours = hours + Sheets("RS Nov 2009").Range("Q" & j).Value
Sheets("NEW").Range("A" & i).Value = Sheets("RS Nov 2009").Range("A" & i).Value
Sheets("NEW").Range("B" & i).Value = hours
End If
Next
Next

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub

Iam getting an error 1004 at
Code:
If Sheets("RS Nov 2009").Range("A" & i).Value = Sheets("RS Nov 2009").Range("A" & j).Value Then

Can anybody help me please?? Thanks in advance :)
 
supcount = 2 (what is this and where did you dimension it?)

hours = hours + Sheets("RS Nov 2009").Range("Q" & j).Value (what is hours = hours + sheets.etc.....?)


I need to start searching from second row hence 2,
And i need to add correspnding hours fo duplicates so hours=hours+sheets...

And also its part of a mucg bigger macro so i cnt just hve a useform, the output sheet of this macro is to be used elsewhere...
 
Upvote 0

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

Forum statistics

Threads
1,215,750
Messages
6,126,663
Members
449,326
Latest member
asp123

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