Excel 2002: Macro for inserting empty rows

M

Mr. Low

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
 
P

Per Jessen

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top