Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1
Default How to insert rows based on change in data

I have a coulumn of data that with several rows of the same data and then the
data changes for several other rows and so on down the sheet. I need to be
able to selcet the column and insert a row between where the data changes.
Almost like doing a subtotal but just inserting a blank row to break up the
data.
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 22,906
Default How to insert rows based on change in data

Assumes the column is A..........(rows.count, 1) change the 1 to suit.

Sub InsertRow_At_Change()
'Sandy Mann July 1st, 2007
Dim LastRow As Long
Dim X As Long
LastRow = Cells(Rows.Count, 1).End(xlUp).Row
Application.ScreenUpdating = False

For X = LastRow To 3 Step -1
If Cells(X, 1).Value < Cells(X - 1, 1).Value Then
If Cells(X, 1).Value < "" Then
If Cells(X - 1, 1).Value < "" Then
Cells(X, 1).EntireRow.Insert Shift:=xlDown
End If
End If
End If
Next X
Application.ScreenUpdating = True
End Sub


Gord Dibben MS Excel MVP


On Wed, 23 Jan 2008 11:14:00 -0800, Leoc wrote:

I have a coulumn of data that with several rows of the same data and then the
data changes for several other rows and so on down the sheet. I need to be
able to selcet the column and insert a row between where the data changes.
Almost like doing a subtotal but just inserting a blank row to break up the
data.


  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,344
Default How to insert rows based on change in data

Hi,

Here is a non-VBA approach:
I am assuming that the items which repeat are in column A.


1. Add a temporary column and enter a formula like the following in C2 the
temporary column:
=IF(A2=A1,0,"T")
2. Copy the formula down. This should put a T on each row where you want to
insert a row.
3. Select from cell C3 down to the bottom and press F5, Special, Formulas,
and uncheck all but Text. Click OK.
4. Press Ctr+ (Ctrl and the Plus key on the number keypad) or Ctrl Shift+
if using the tip row of numbers. Choose Entire Row.
5. Remove the dummy column.

If you code this you will find it is faster than the For loop approach.
--
Cheers,
Shane Devenshire


"Leoc" wrote:

I have a coulumn of data that with several rows of the same data and then the
data changes for several other rows and so on down the sheet. I need to be
able to selcet the column and insert a row between where the data changes.
Almost like doing a subtotal but just inserting a blank row to break up the
data.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert rows based on specific value bob Excel Worksheet Functions 6 February 29th 08 07:11 PM
Insert new rows based on Data in other rows mg_sv_r Excel Worksheet Functions 5 November 21st 07 01:51 PM
Insert Rows Based on values in another worksheet Jason Excel Discussion (Misc queries) 3 June 24th 07 01:13 PM
Insert New Rows based on COUNTA() TheDPQ New Users to Excel 2 January 28th 06 03:07 AM
Insert a number of rows based on a value in a cell on active row iRocco Excel Discussion (Misc queries) 1 August 11th 05 06:18 AM


All times are GMT +1. The time now is 07:18 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"