Advertisement
Guest User

Untitled

a guest
Feb 27th, 2015
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. Staff Locations Roles
  2. 1 Location1 Role1
  3. 1 Location2 Role1
  4. 2 Location2 Role2
  5. 3 Location3 Role3
  6. 3 Location3 Role4
  7.  
  8. Staff Locations Roles
  9. 1 Location1, Location2 Role1
  10. 2 Location2 Role2
  11. 3 Location3 Role3
  12. 3 Location3 Role4
  13.  
  14. Sub Sort_Duplicates()
  15.  
  16. Dim lngRow, lngRow2 As Long
  17.  
  18. With ActiveSheet
  19. Dim flag As Integer: flag = 0
  20. Dim i As Integer
  21. Dim columnToMatch As Integer: columnToMatch = 1
  22. Dim column2ToMatch As Integer: column2ToMatch = 3
  23. Dim columnToConcatenate As Integer: columnToConcatenate = 2
  24.  
  25. lngRow = .Cells(538537, columnToMatch).End(xlUp).Row
  26. .Cells(columnToMatch).CurrentRegion.Sort key1:=.Cells(columnToMatch), Header:=xlYes
  27.  
  28. Do
  29. If .Cells(lngRow, columnToMatch) = .Cells(lngRow - 1, columnToMatch) Then
  30. 'flag = 1
  31. i = 1
  32. lngRow2 = lngRow
  33. Do While Cells(lngRow2, columnToMatch) = .Cells(lngRow2 - i, columnToMatch)
  34. If .Cells(lngRow2, column2ToMatch) = .Cells(lngRow2 - i, column2ToMatch) Then
  35. .Cells(lngRow2, columnToConcatenate) = .Cells(lngRow2, columnToConcatenate) & ", " & .Cells(lngRow2 - i, columnToConcatenate)
  36. .Rows(lngRow2 - i).Delete
  37. End If
  38. i = i + 1
  39. Loop
  40. lngRow2 = lngRow2 - 1
  41. End If
  42.  
  43. ' If flag = 1 Then
  44. ' lngRow = lngRow2
  45. ' flag = 0
  46. ' Else
  47. lngRow = lngRow - 1
  48. 'End If
  49. Loop Until lngRow = 1
  50. End With
  51. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement