![]() |
Excel 2002: Macro for inserting empty rows
Hi,
I have the folowing table: A B C D E Flight Fare Type 1 M21 2,250 1 2 H32 2,530 1 3 T30 850 2 4 Q41 750 2 5 C47 650 2 6 Q21 3,650 8 7 Q72 3,820 8 5000 Column C is sorted in ascending order. May I know the marco code that I need to run in order to insert an empty row when the type changes ? If column C is now moved to column E, how you code should be modified ? Thanks Low -- A36B58K641 |
Excel 2002: Macro for inserting empty rows
Hi
Look at this, just change the letter in the TargetCol variable to change column: Sub InsertRows() TargetCol = "C" StartRow = 2 'Headings in row 1 LastRow = Range(TargetCol & Rows.Count).End(xlUp).Row For r = LastRow To StartRow + 1 Step -1 If Range(TargetCol & r).Value < Range(TargetCol & r - 1).Value Then Rows(r).Insert End If Next End Sub Hopes this helps. --- Per On 13 Apr., 14:39, Mr. Low wrote: Hi, I have the folowing table: * * * * * * *A * * * * * * B * * * * * * * *C * * * * * * * * *D * * * * * * * * * E * * * * * *Flight * * * Fare * * * * *Type 1 * * * * M21 * * *2,250 * * * * * * *1 2 * * * * H32 * * * 2,530 * * * * * * 1 3 * * * * T30 * * * * *850 * * * * * * 2 4 * * * * Q41 * * * * 750 * * * * * * *2 5 * * * * C47 * * * * *650 * * * * * * 2 6 * * * * Q21 * * * 3,650 * * * * * * 8 7 * * * * Q72 * * * 3,820 * * * * * * 8 5000 Column C is sorted in ascending order. May I know the marco code that I need to run in order to insert an empty row *when the type changes ? If column C is now moved to column E, how you code should be modified *? Thanks Low -- A36B58K641 |
All times are GMT +1. The time now is 12:01 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com