Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Ronald \Tony\ Johnson
 
Posts: n/a
Default Insert Row When Column Amount Changes

Here is an example of what I am talking about.

A B C D
1 A B C D
2 2 41100 274 584
3 2 41100 274 625
4 2 41100 274 333
5 2 41100 274 102
6 2 41100 274 957
7 2 41100 274 362
8 2 41100 274 651
9 2 41100 274 611
10 2 41100 284 965
11 2 41100 284 336
12 2 41100 284 251
13 2 41100 284 362
14 2 41100 284 859
15 2 41100 284 512
16 2 41100 284 669
17 2 41100 284 512


I need to insert a new row every time the amount in Column "C"
changes to a different amount than the previous one.
There are approx 16,000 rows in this file or I would not be asking..lol

Thanks for any help you can offer.


--
Tony Johnson

--
Tony Johnson
  #2   Report Post  
galimi
 
Posts: n/a
Default

Tony,

You can have a row insert automatically with the following code embedded as
a change event for the sheet in question.

Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False


If Target.Column = 3 Then
Target.Rows.Insert
End If
Application.EnableEvents = True

End Sub

A better way to do this would be to have an add-in that activates a
withevents class intercept of all Worksheet Change events.
--
http://HelpExcel.com
1-888-INGENIO
1-888-464-3646
x0197758


"Ronald "Tony" Johnson" wrote:

Here is an example of what I am talking about.

A B C D
1 A B C D
2 2 41100 274 584
3 2 41100 274 625
4 2 41100 274 333
5 2 41100 274 102
6 2 41100 274 957
7 2 41100 274 362
8 2 41100 274 651
9 2 41100 274 611
10 2 41100 284 965
11 2 41100 284 336
12 2 41100 284 251
13 2 41100 284 362
14 2 41100 284 859
15 2 41100 284 512
16 2 41100 284 669
17 2 41100 284 512


I need to insert a new row every time the amount in Column "C"
changes to a different amount than the previous one.
There are approx 16,000 rows in this file or I would not be asking..lol

Thanks for any help you can offer.


--
Tony Johnson

--
Tony Johnson

  #3   Report Post  
Jim May
 
Posts: n/a
Default

The below code works in an example I have - based on a change in Column A (in my example).
Adapt to your needs (Chg A to C)..

Sub InsertRow_A_Chg()
Dim Lrow As Long, vcurrent As String, i As Long
'// find last used cell in Column A
Lrow = Cells(Rows.Count, "A").End(xlUp).Row
'// get the value of that cell in Column A (column 1)
vcurrent = Cells(Lrow, 1).Value
'// rows are inserted by looping from bottom up
For i = Lrow To 2 Step -1
If Cells(i, 1).Value < vcurrent Then
vcurrent = Cells(i, 1).Value
Rows(i + 1).Resize(2).Insert 'Rows(i + 1).Insert to only Insert One Blank Row
End If
Next i
End Sub

Hope this helps,
Jim May
"Ronald "Tony" Johnson" wrote in message ...
Here is an example of what I am talking about.

A B C D
1 A B C D
2 2 41100 274 584
3 2 41100 274 625
4 2 41100 274 333
5 2 41100 274 102
6 2 41100 274 957
7 2 41100 274 362
8 2 41100 274 651
9 2 41100 274 611
10 2 41100 284 965
11 2 41100 284 336
12 2 41100 284 251
13 2 41100 284 362
14 2 41100 284 859
15 2 41100 284 512
16 2 41100 284 669
17 2 41100 284 512


I need to insert a new row every time the amount in Column "C"
changes to a different amount than the previous one.
There are approx 16,000 rows in this file or I would not be asking..lol

Thanks for any help you can offer.


--
Tony Johnson

--
Tony Johnson
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
How to group similar column titles together???? vrk1 Excel Discussion (Misc queries) 2 April 30th 05 12:17 AM
insert column move object markg Excel Discussion (Misc queries) 3 April 26th 05 03:52 PM
Formula for a column comicfly Excel Discussion (Misc queries) 2 March 11th 05 12:16 PM
Lookup then Match and insert value from next column Tenacity Excel Worksheet Functions 3 March 4th 05 02:49 AM
Auto Insert of Rows Gar3th Excel Worksheet Functions 0 January 6th 05 08:33 PM


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

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

About Us

"It's about Microsoft Excel"