Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. Name Sales
  2. ---------------------------------
  3. Thomas 100
  4. Jay 200
  5. Thomas 100
  6. Mathew 50
  7.  
  8. Name Sales
  9. ---------------------------------
  10. Thomas 200
  11. Jay 200
  12. Mathew 50
  13.  
  14. 'Combine duplicate rows and sum values
  15.  
  16. Dim Rng As Range
  17. Dim LngRow As Long, i As Long
  18. Dim pct As Integer
  19. pct = 45
  20.  
  21. LngLastRow = lRow 'The last row is calculated somewhere above...
  22.  
  23. 'Initializing the first row
  24. i = 1
  25.  
  26. 'Looping until blank cell is encountered in first column
  27. While Not Cells(i, 1).Value = ""
  28.  
  29. 'Initializing range object
  30. Set Rng = Cells(i, 1)
  31.  
  32. 'Looping from last row to specified first row
  33. For LngRow = LngLastRow To (i + 1) Step -1
  34.  
  35. 'Checking whether value in the cell is equal to specified cell
  36. If Cells(LngRow, 1).Value = Rng.Value Then
  37. Rng.Offset(0, 1).Value = Rng.Offset(0, 1).Value + Cells(LngRow, 2).Value
  38. Rows(LngRow).Delete
  39. End If
  40.  
  41. Next LngRow
  42.  
  43. i = i + 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement