Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Name Sales
- ---------------------------------
- Thomas 100
- Jay 200
- Thomas 100
- Mathew 50
- Name Sales
- ---------------------------------
- Thomas 200
- Jay 200
- Mathew 50
- 'Combine duplicate rows and sum values
- Dim Rng As Range
- Dim LngRow As Long, i As Long
- Dim pct As Integer
- pct = 45
- LngLastRow = lRow 'The last row is calculated somewhere above...
- 'Initializing the first row
- i = 1
- 'Looping until blank cell is encountered in first column
- While Not Cells(i, 1).Value = ""
- 'Initializing range object
- Set Rng = Cells(i, 1)
- 'Looping from last row to specified first row
- For LngRow = LngLastRow To (i + 1) Step -1
- 'Checking whether value in the cell is equal to specified cell
- If Cells(LngRow, 1).Value = Rng.Value Then
- Rng.Offset(0, 1).Value = Rng.Offset(0, 1).Value + Cells(LngRow, 2).Value
- Rows(LngRow).Delete
- End If
- Next LngRow
- i = i + 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement