#1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Tom
 
Posts: n/a
Default Inserting a row

Using a macro:
In a worksheet I would like for a row to be inserted if in a column the next
number is different.

example: in Column E

Before After
03279090 03279090
03279090 03279090
03299880
03299880 03299880
03299880 03299880
03299880

TFTH,
Tom



  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
vezerid
 
Posts: n/a
Default Inserting a row

To, the following macro should do your job:

Sub InsertRows()

StartRow = 2 'Change the 2 to the row actual data start
DataColumn = 5 'Change the 1 to the column where your data is

i = StartRow + 1
While Cells(i, DataColumn) < ""
If Cells(i, DataColumn) < Cells(i - 1, DataColumn) Then
Cells(i, DataColumn).EntireRow.Insert
i = i + 1
End If
i = i + 1
Wend
End Sub


-------------------------------------
To run it:
Alt+F11 for the VB editor
menu command Insert | Module
Paste the code above

From Excel: Alt+F8


  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Herbert Seidenberg
 
Posts: n/a
Default Inserting a row

Or without VBA...
Enter this formula at B2 and copy down:
=--(A1=A2)
Copy Paste Special Value
Go To Special Column Differences
Insert Entire Row

  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Kevin Vaughn
 
Posts: n/a
Default Inserting a row

This seems to work except when there is a single instance interspersed in the
data.
If there is a single instance, it appears to insert 2 rows above the 1st
difference and none above the 2nd.

3279090
3279090 TRUE


3280000 FALSE
3299880 FALSE
3299880 TRUE
3299880 TRUE

Otherwise, that was a very interesting trick.
--
Kevin Vaughn


"Herbert Seidenberg" wrote:

Or without VBA...
Enter this formula at B2 and copy down:
=--(A1=A2)
Copy Paste Special Value
Go To Special Column Differences
Insert Entire Row


  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Kevin Vaughn
 
Posts: n/a
Default Inserting a row

I noticed I hadn't entered my formula exactly like yours, but even after
making the change, result was the same (I hadn't used the --() construct.)
--
Kevin Vaughn


"Kevin Vaughn" wrote:

This seems to work except when there is a single instance interspersed in the
data.
If there is a single instance, it appears to insert 2 rows above the 1st
difference and none above the 2nd.

3279090
3279090 TRUE


3280000 FALSE
3299880 FALSE
3299880 TRUE
3299880 TRUE

Otherwise, that was a very interesting trick.
--
Kevin Vaughn


"Herbert Seidenberg" wrote:

Or without VBA...
Enter this formula at B2 and copy down:
=--(A1=A2)
Copy Paste Special Value
Go To Special Column Differences
Insert Entire Row




  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Herbert Seidenberg
 
Posts: n/a
Default Inserting a row

Kevin,
Thanks for pointing out the exception.
Here is a procedure that tolerates non-repeating data.
Enter this formula into B2 and copy down:
=--NOT((A1<A2)*(B1=1))
Enter this formula into C2 and copy down:
=--(--(A1=A2)=B2)
Select the data in B and C and
Copy Paste Special Value
Go To Special Column Differences
Insert Entire Row

This now opens up a whole lot of possibilities, like
inserting blanks at alternate rows.
Herb

  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Kevin Vaughn
 
Posts: n/a
Default Inserting a row

That works for me up until the point where I actually insert rows. When I go
to special / column differences, I can tell that it is selecting the rows
that should make it work (ones with differences,) but when I hit insert rows
(or insert entire rows) it does not insert rows where I expect it to. I am
using 2000. Is that the difference?
--
Kevin Vaughn


"Herbert Seidenberg" wrote:

Kevin,
Thanks for pointing out the exception.
Here is a procedure that tolerates non-repeating data.
Enter this formula into B2 and copy down:
=--NOT((A1<A2)*(B1=1))
Enter this formula into C2 and copy down:
=--(--(A1=A2)=B2)
Select the data in B and C and
Copy Paste Special Value
Go To Special Column Differences
Insert Entire Row

This now opens up a whole lot of possibilities, like
inserting blanks at alternate rows.
Herb


  #8   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Herbert Seidenberg
 
Posts: n/a
Default Inserting a row

Try inserting a 1 into B1 and C1.
Otherwise, please post the number sequence you are using
and point to the place where you expect different results.

  #9   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Kevin Vaughn
 
Posts: n/a
Default Inserting a row

This did the trick. However, to make sure, I went in and deleted the entries
in B1 and C1, re-entered the formulae and tried the sequence again and it
also worked. So apparently at some point, I took a wrong step that
propogated to future testings. Sorry about that and thanks.
--
Kevin Vaughn


"Herbert Seidenberg" wrote:

Try inserting a 1 into B1 and C1.
Otherwise, please post the number sequence you are using
and point to the place where you expect different results.


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
Reference the same row from another sheet after inserting a new ro Brian Excel Worksheet Functions 1 April 2nd 23 12:54 PM
Inserting Objects BeanyBabe Excel Discussion (Misc queries) 1 December 19th 05 10:38 PM
Separate 5digits by inserting - Faio Excel Worksheet Functions 4 December 1st 05 03:17 AM
Inserting a number and having it displayed as you typed Bev New Users to Excel 2 August 23rd 05 01:54 AM
Inserting Footer - Ajit Ajit Munj Excel Discussion (Misc queries) 2 March 11th 05 02:39 PM


All times are GMT +1. The time now is 12:04 AM.

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"