Hi,
I've got a spreadsheet with lots of company names in column A and various different figures in columns B through to a number that changes often. If the names are the same, I'd like to add all the corresponding values and be left with unique entries in A. This block does the job but i have to run it two or three times so it catches everything, as some companies are repeated ten+ times. Can anybody see a more elegant and error-proof way of coding this?
For a = 2 To x
For b = 1 To x
If Worksheets(SheetName).Cells(a, 1).Value = Worksheets(SheetName).Cells(a, 1).Offset(b, 0).Value Then
For Col = 2 To 8
ValueA = Worksheets(SheetName).Cells(a, Col).Value
ValueB = Worksheets(SheetName).Cells(a, Col).Offset(b, 0).Value
NewValue = ValueA + ValueB
Worksheets(SheetName).Cells(a, Col).Value = NewValue
Next Col
Worksheets(SheetName).Cells(a, 1).Offset(b, 0).EntireRow.Delete
End If
Next b
Next a
Thanks,
Kate
I've got a spreadsheet with lots of company names in column A and various different figures in columns B through to a number that changes often. If the names are the same, I'd like to add all the corresponding values and be left with unique entries in A. This block does the job but i have to run it two or three times so it catches everything, as some companies are repeated ten+ times. Can anybody see a more elegant and error-proof way of coding this?
For a = 2 To x
For b = 1 To x
If Worksheets(SheetName).Cells(a, 1).Value = Worksheets(SheetName).Cells(a, 1).Offset(b, 0).Value Then
For Col = 2 To 8
ValueA = Worksheets(SheetName).Cells(a, Col).Value
ValueB = Worksheets(SheetName).Cells(a, Col).Offset(b, 0).Value
NewValue = ValueA + ValueB
Worksheets(SheetName).Cells(a, Col).Value = NewValue
Next Col
Worksheets(SheetName).Cells(a, 1).Offset(b, 0).EntireRow.Delete
End If
Next b
Next a
Thanks,
Kate