close

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

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) lt;gt; quot;quot;
If Cells(i, DataColumn) lt;gt; 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

gt;From Excel: Alt F8Or without VBA...
Enter this formula at B2 and copy down:
=--(A1=A2)
Copy gt; Paste Special gt; Value
Go To gt; Special gt; Column Differences
Insert gt; Entire RowThis 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
3279090TRUE3280000FALSE
3299880FALSE
3299880TRUE
3299880TRUE

Otherwise, that was a very interesting trick.
--
Kevin Vaughnquot;Herbert Seidenbergquot; wrote:

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

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 Vaughnquot;Kevin Vaughnquot; wrote:

gt; This seems to work except when there is a single instance interspersed in the
gt; data.
gt; If there is a single instance, it appears to insert 2 rows above the 1st
gt; difference and none above the 2nd.
gt;
gt; 3279090
gt; 3279090TRUE
gt;
gt;
gt; 3280000FALSE
gt; 3299880FALSE
gt; 3299880TRUE
gt; 3299880TRUE
gt;
gt; Otherwise, that was a very interesting trick.
gt; --
gt; Kevin Vaughn
gt;
gt;
gt; quot;Herbert Seidenbergquot; wrote:
gt;
gt; gt; Or without VBA...
gt; gt; Enter this formula at B2 and copy down:
gt; gt; =--(A1=A2)
gt; gt; Copy gt; Paste Special gt; Value
gt; gt; Go To gt; Special gt; Column Differences
gt; gt; Insert gt; Entire Row
gt; gt;
gt; gt;

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((A1lt;gt;A2)*(B1=1))
Enter this formula into C2 and copy down:
=--(--(A1=A2)=B2)
Select the data in B and C and
Copy gt; Paste Special gt; Value
Go To gt; Special gt; Column Differences
Insert gt; Entire Row

This now opens up a whole lot of possibilities, like
inserting blanks at alternate rows.
HerbThat 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 Vaughnquot;Herbert Seidenbergquot; wrote:

gt; Kevin,
gt; Thanks for pointing out the exception.
gt; Here is a procedure that tolerates non-repeating data.
gt; Enter this formula into B2 and copy down:
gt; =--NOT((A1lt;gt;A2)*(B1=1))
gt; Enter this formula into C2 and copy down:
gt; =--(--(A1=A2)=B2)
gt; Select the data in B and C and
gt; Copy gt; Paste Special gt; Value
gt; Go To gt; Special gt; Column Differences
gt; Insert gt; Entire Row
gt;
gt; This now opens up a whole lot of possibilities, like
gt; inserting blanks at alternate rows.
gt; Herb
gt;
gt;

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.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 Vaughnquot;Herbert Seidenbergquot; wrote:

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

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 software 的頭像
    software

    software

    software 發表在 痞客邦 留言(0) 人氣()