Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. Sub AlignData()
  2. Const FIRST_ROW As Long = 2 ' So you can skip a header row, or multiple rows
  3. Const MAIN_COLUMN As Long = 1 ' this is your primary ID field
  4. Const CHILD_COLUMN As Long = 7 ' this is your alternate ID field (the one we want to push down)
  5. Const SHIFT_START As String = "G" ' the first column to push
  6. Const SHIFT_END As String = "O" ' the last column to push
  7.  
  8. Dim row As Long
  9. row = FIRST_ROW
  10. Dim xs As Worksheet
  11. Set xs = ActiveSheet
  12. Dim im_done As Boolean
  13. im_done = False
  14. Do Until im_done
  15. If WorksheetFunction.CountA(xs.Rows(row)) = 0 Then
  16. im_done = True
  17. Else
  18. If xs.Cells(row, MAIN_COLUMN).Value < xs.Cells(row, CHILD_COLUMN).Value Then
  19. xs.Range(Cells(row, SHIFT_START), Cells(row, SHIFT_END)).Insert Shift:=xlDown
  20. Debug.Print "Pushed row: " & row & " down!"
  21. End If
  22. row = row + 1
  23. End If
  24. Loop
  25. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement