Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub AlignData()
- Const FIRST_ROW As Long = 2 ' So you can skip a header row, or multiple rows
- Const MAIN_COLUMN As Long = 1 ' this is your primary ID field
- Const CHILD_COLUMN As Long = 7 ' this is your alternate ID field (the one we want to push down)
- Const SHIFT_START As String = "G" ' the first column to push
- Const SHIFT_END As String = "O" ' the last column to push
- Dim row As Long
- row = FIRST_ROW
- Dim xs As Worksheet
- Set xs = ActiveSheet
- Dim im_done As Boolean
- im_done = False
- Do Until im_done
- If WorksheetFunction.CountA(xs.Rows(row)) = 0 Then
- im_done = True
- Else
- If xs.Cells(row, MAIN_COLUMN).Value < xs.Cells(row, CHILD_COLUMN).Value Then
- xs.Range(Cells(row, SHIFT_START), Cells(row, SHIFT_END)).Insert Shift:=xlDown
- Debug.Print "Pushed row: " & row & " down!"
- End If
- row = row + 1
- End If
- Loop
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement