Here is the beginning file.
Here is the code I'm using.
Sub CopyPayeeCode()
Dim Rng As Range
For Each Rng In Range("C8", Range("C" & Rows.Count).End(xlUp)).SpecialCells(xlConstants).Areas
Rng.Offset(-1, -2).Resize(Rng.Count + 1, 2).FillDown
Next Rng
End Sub
Sub DeleteBlankRows()
Range("D6", Range("D" & Rows.Count).End(xlUp)).SpecialCells(xlBlanks).EntireRow.Delete
End Sub
Sub InsertRow5()
Rows(5).Insert
End Sub
Sub SortByD()
Range("A6").CurrentRegion.Sort Range("D6"), xlAscending, Range("A6"), , xlAscending, Header:=xlYes
End Sub
Sub InsertRowsAtValueChangeColumnB()
Dim X As Long, LastRow As Long
Const DataCol As String = "D"
Const StartRow = 3
LastRow = Cells(Rows.Count, DataCol).End(xlUp).Row
Application.ScreenUpdating = False
For X = LastRow To StartRow + 1 Step -1
If Cells(X, DataCol).Value <> Cells(X - 1, DataCol) Then Rows(X).Insert
Next
Application.ScreenUpdating = True
End Sub
Sub DeleteRow5()
Rows(5).Delete
End Sub
Sub DeleteRow6()
Rows(6).Delete
End Sub
Sub Automation()
Call CopyPayeeCode
Call DeleteBlankRows
Call InsertRow5
Call SortByD
Call InsertRowsAtValueChangeColumnB
Call InsertRowsAtValueChangeColumnB
Call DeleteRow5
Call DeleteRow5
Call DeleteRow5
Call DeleteRow6
Call DeleteRow6
Call DeleteRow6
End Sub
Here is the final product
What I'm trying to do here is find a more efficient way sort, insert, and delete rows. I only know how to do it by repeating the code. When inserting the column with code "InsertRowsAtValueChangeColumnB" I would like for it to insert 3 rows, but my code is only inserting one row on the first go around, and upon repeating it a second time it inserts the extra rows.
I also don't know how to tell it to delete rows 5,6, and 7 therefore I'm just repeating the macros.
Any tips are welcome, very new to this but this is very interesting.
Here is the code I'm using.
Sub CopyPayeeCode()
Dim Rng As Range
For Each Rng In Range("C8", Range("C" & Rows.Count).End(xlUp)).SpecialCells(xlConstants).Areas
Rng.Offset(-1, -2).Resize(Rng.Count + 1, 2).FillDown
Next Rng
End Sub
Sub DeleteBlankRows()
Range("D6", Range("D" & Rows.Count).End(xlUp)).SpecialCells(xlBlanks).EntireRow.Delete
End Sub
Sub InsertRow5()
Rows(5).Insert
End Sub
Sub SortByD()
Range("A6").CurrentRegion.Sort Range("D6"), xlAscending, Range("A6"), , xlAscending, Header:=xlYes
End Sub
Sub InsertRowsAtValueChangeColumnB()
Dim X As Long, LastRow As Long
Const DataCol As String = "D"
Const StartRow = 3
LastRow = Cells(Rows.Count, DataCol).End(xlUp).Row
Application.ScreenUpdating = False
For X = LastRow To StartRow + 1 Step -1
If Cells(X, DataCol).Value <> Cells(X - 1, DataCol) Then Rows(X).Insert
Next
Application.ScreenUpdating = True
End Sub
Sub DeleteRow5()
Rows(5).Delete
End Sub
Sub DeleteRow6()
Rows(6).Delete
End Sub
Sub Automation()
Call CopyPayeeCode
Call DeleteBlankRows
Call InsertRow5
Call SortByD
Call InsertRowsAtValueChangeColumnB
Call InsertRowsAtValueChangeColumnB
Call DeleteRow5
Call DeleteRow5
Call DeleteRow5
Call DeleteRow6
Call DeleteRow6
Call DeleteRow6
End Sub
Here is the final product
What I'm trying to do here is find a more efficient way sort, insert, and delete rows. I only know how to do it by repeating the code. When inserting the column with code "InsertRowsAtValueChangeColumnB" I would like for it to insert 3 rows, but my code is only inserting one row on the first go around, and upon repeating it a second time it inserts the extra rows.
I also don't know how to tell it to delete rows 5,6, and 7 therefore I'm just repeating the macros.
Any tips are welcome, very new to this but this is very interesting.