Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Autoinsert Rows

Status
Not open for further replies.

Verner

Mining
Jul 7, 2003
24
I have a large chunk of some production data - some 4000 lines and have it sorted by date. Is there a way to automatically segment the data so that I can put in a line or two under each date or to separate the data day-by-day so that I can minipulate certaion portions of the data?
 
Replies continue below

Recommended for you

How would a couple blank lines in a 4000-line file help you any? You could write a macro takes each date's data and put it onto a separate sheet. Surely that would be more useful than blank lines?

How do you want to manipulate the data? Would a simple filter do the trick for you?

 
Perhaps I've missed something here, but this is very easy to do in a VB Macro. If each row contains data for an individual date, the following code will insert 2 rows under each date ...

Sub insert_rows()

' Last row with data in it
last_data_row = 4000
' Number of rows to insert
numrows=2
For i = last_data_row To 1 Step -1
Rows(i & ":" & (i + (numrows-1))).Select
Selection.Insert Shift:=xlDown
Next i
End Sub
 
This will do what you want provided, as you mention, the spreadsheet is sorted on column A.

This routine does the following:
1. Determine the last row used.
2. Working from the last row used upwards it compares
the value of column A in the current row to column A in
the row above.
if they are the same nothing happens.
If they differ then 2 rows are inserted.

Dim i As Long, LastRow As Long
Application.ScreenUpdating = False
'finds last used row in column A
LastRow = Range("A65536").End(xlUp).Row
For i = LastRow To 1 Step -1
If i >= 2 Then
If Cells(i, "A") <> Cells(i - 1, "A") Then
Rows(i).Insert 'add 1 blank row
Rows(i).Insert 'add another blank row
End If
Else
End
End If
Next i
Application.ScreenUpdating = True
 
I use the ASAP "smart difference" function to insert formatting, blank lines or page breaks just as you desire. I am not sure if it is allowed to mention specific companies, so feel free to red flag this if it is not appropriate.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor