A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Insert rows when data changes



 
 
Thread Tools Display Modes
  #1  
Old May 10th, 2010, 03:26 PM posted to microsoft.public.excel.misc
Russell Dawson[_2_]
external usenet poster
 
Posts: 173
Default Insert rows when data changes

In a column of periodically changing names in alphabetical order (col A) – I
need to insert a row after each change in initial letter. So when the names
have been sorted when the initial letter of the name changes from A to B as
in Aldred to Bute there is a blank row inserted after Aldred.

It would be nice if the code could include the instruction to sort the names
first rather than that being a separate action. Sort by column A to include
other related data in columns to F.

Thanks
--
Russell Dawson
Excel Student

Please hit "Yes" if this post was helpful.
  #2  
Old May 10th, 2010, 04:10 PM posted to microsoft.public.excel.misc
Don Guillett[_2_]
external usenet poster
 
Posts: 607
Default Insert rows when data changes

Sub Sort_InsertRowsSAS()
lr = Cells(Rows.Count, 1).End(xlUp).Row
Range("A1:A" & lr).Sort Key1:=Range("A1"), Order1:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom
For i = lr To 2 Step -1
If Cells(i - 1, 1) Cells(i, 1) Then Rows(i).Insert
Next i
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Russell Dawson" wrote in message
...
In a column of periodically changing names in alphabetical order (col A) –
I
need to insert a row after each change in initial letter. So when the
names
have been sorted when the initial letter of the name changes from A to B
as
in Aldred to Bute there is a blank row inserted after Aldred.

It would be nice if the code could include the instruction to sort the
names
first rather than that being a separate action. Sort by column A to
include
other related data in columns to F.

Thanks
--
Russell Dawson
Excel Student

Please hit "Yes" if this post was helpful.


  #3  
Old May 10th, 2010, 04:13 PM posted to microsoft.public.excel.misc
Dave Peterson[_2_]
external usenet poster
 
Posts: 69
Default Insert rows when data changes

I'd add an additional column (a new column A) with a formula like:

=left(b2,1)
and fill down.

Then I could use data|subtotals to group by this column.

If I wanted it reproduced mechanically, I'd record a macro when:
I removed data|subtotals (Remove all)
Sorted the data by column A (ascending) and column B (ascending)
Reapplied data|subtotals



Russell Dawson wrote:
In a column of periodically changing names in alphabetical order (col A) – I
need to insert a row after each change in initial letter. So when the names
have been sorted when the initial letter of the name changes from A to B as
in Aldred to Bute there is a blank row inserted after Aldred.

It would be nice if the code could include the instruction to sort the names
first rather than that being a separate action. Sort by column A to include
other related data in columns to F.

Thanks


--

Dave Peterson
  #4  
Old May 10th, 2010, 04:21 PM posted to microsoft.public.excel.misc
Mike H
external usenet poster
 
Posts: 8,419
Default Insert rows when data changes


Russell,

Try this macro which does the sort and insert the rows. Change SHT tp your
sheet

Sub insertrowifnamechg()
MyColumn = "A"
Set sht = Sheets("Sheet1")
With sht
'Sort data
..Columns("A:F").Sort Key1:=.Range("A1"), Order1:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
'Insert rows
For x = .Cells(Rows.Count, MyColumn).End(xlUp).Row To 2 Step -1
If Left(.Cells(x - 1, MyColumn), 1) _
Left(.Cells(x, MyColumn), 1) Then .Rows(x).Insert
Next x
End With
End Sub




--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Russell Dawson" wrote:

In a column of periodically changing names in alphabetical order (col A) – I
need to insert a row after each change in initial letter. So when the names
have been sorted when the initial letter of the name changes from A to B as
in Aldred to Bute there is a blank row inserted after Aldred.

It would be nice if the code could include the instruction to sort the names
first rather than that being a separate action. Sort by column A to include
other related data in columns to F.

Thanks
--
Russell Dawson
Excel Student

Please hit "Yes" if this post was helpful.

  #6  
Old May 10th, 2010, 05:32 PM posted to microsoft.public.excel.misc
Russell Dawson[_2_]
external usenet poster
 
Posts: 173
Default Insert rows when data changes

Many thanks for the answers.


--
Russell Dawson
Excel Student

Please hit "Yes" if this post was helpful.


"Russell Dawson" wrote:

In a column of periodically changing names in alphabetical order (col A) – I
need to insert a row after each change in initial letter. So when the names
have been sorted when the initial letter of the name changes from A to B as
in Aldred to Bute there is a blank row inserted after Aldred.

It would be nice if the code could include the instruction to sort the names
first rather than that being a separate action. Sort by column A to include
other related data in columns to F.

Thanks
--
Russell Dawson
Excel Student

Please hit "Yes" if this post was helpful.

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 02:28 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.