Inserting a single row to separate data multiple times

G

Guest

How do I insert a row for every change in value for column C?

I need it to separate data
Currently I sort the spreadsheet and then scroll thru the entire thing
inserting rows for each variable listed in column C.

Example: Value in rows 1 thru 5 of column C are 27; and the value in rows 6
thru 8 are 28; rows 9 & 10 are 29 and so on and so on.
 
D

Dave Peterson

First add a header row if you haven't.

Then after you sort your data, select the data (header row through the last row
of data) and do:
Data|subtotals

And follow the wizard from there.

You can even add subtotals to columns/fields that you want!
 
G

Guest

Try this:

Sub InsertRow()

With Worksheets("sheet1") '<=== change to suit
Lastrow = .Cells(Rows.Count, "C").End(xlUp).Row
For irow = Lastrow To 2 Step -1
If .Cells(irow - 1, "C") <> .Cells(irow, "C") Then
Rows(irow).Insert Shift:=xlDown
End If
Next
End With
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top