VBA : Aggregating Excel cells whose rows contain certain text

In VBA, I want to write a Macro that aggregates the values of a column depending on the text values of another column.
For eaxmple, I have data like this:


Name   Salary
RON         5
TOM         6
JO            4
RON          3
RON         2
JO           10

I want to write something in VBA where I take this date and run a macro to generate:

Name      Salary
RON       10
TOM        6
JO           14

In reality, the raw file contains about 800 lines of data and the cells will not always be in the same place.

Any ideas?
ronanm1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

david_barkerCommented:
Assuming data is in the first 2 columns, and that the result should go to the third and fourth column :

Public Sub Salary()
  Dim aNames(1 To 100) As String
  Dim aSalary(1 To 100) As Integer
  Dim iNext  As Integer
  Dim bFound As Boolean
 
  iNext = 1
  For iRow = 1 To 800
    sName = ActiveSheet.Cells(iRow, 1)
    If sName = "" Then Exit For
    iSalary = ActiveSheet.Cells(iRow, 2)
    bFound = False
    For iLoop = 1 To iNext
      If aNames(iLoop) = sName Then
        aSalary(iLoop) = aSalary(iLoop) + iSalary
        bFound = True
        Exit For
      End If
    Next iLoop
    If Not bFound Then
      aNames(iNext) = sName
      aSalary(iNext) = iSalary
      iNext = iNext + 1
    End If
  Next iRow
 
  For iRow = 1 To iNext - 1
    ActiveSheet.Cells(iRow, 3) = aNames(iRow)
    ActiveSheet.Cells(iRow, 4) = aSalary(iRow)
  Next iRow
 
End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
huntersvcsCommented:
This might be easier:

ActiveCell.FormulaR1C1 = "=SUMIF(R[-8]C[1]:R[-2]C[1],""Ron."",R[-8]C:R[-2]C)"
ActiveCell.FormulaR1C1 = "=SUMIF(R[-8]C[1]:R[-2]C[1],""Tom."",R[-8]C:R[-2]C)"
ActiveCell.FormulaR1C1 = "=SUMIF(R[-8]C[1]:R[-2]C[1],""Jo."",R[-8]C:R[-2]C)"

You just have to set the variables for the rows and columns, but that's easy!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.