PDA

View Full Version : [SOLVED:] Add certain amount of rows to last rows per chapter



nugol
03-30-2016, 03:15 AM
Hy folks,

kind of specific but I try my best. Thing is i have a column where in the first 30 rows there is data, then a summary, a break and then there is the same again.
Example:

ColumnA
Data1
Data2
Data3
...
Summary

emptyrow

Data5
Data6
...
Summary

Now I try to tell excel to add a certain amount of rows to the first paragraph (cellswithcriteria) and then some rows to the next paragraph.
That is my code so far.


Dim cellswithcirteria As Variant
Dim cellswithoutcriteria As Variant
cellswithcirteria = Range("D2").Value
cellswithoutcriteria = Range("E2").Value

Range("A1").Select
Selection.End(xlDown).Select
Rows("6:6").Select 'here it should add as many rows as the cellswithcriteria value is
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove

Selection.End(xlDown).Select
Selection.End(xlDown).Select
Selection.End(xlDown).Select
Rows("15:15").Select 'here it should add as many rows as the cellswithcriteria value is
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove


Any ideas?

nugol
03-31-2016, 01:56 AM
That did the trick.


Dim cellswithcirteria As Variant
Dim cellswithoutczuriteria As Variant
cellswithcirteria = Sheets("table2").Range("D2").Value
cellswithoutcriteria = Sheets("table2").Range("E2").Value
Range("C8").Select
Selection.End(xlDown).Select
Range(ActiveCell, ActiveCell.Offset((cellswithcirteria), 0)).EntireRow.Insert