Inserting Row after data change

A

ATanker62

Hello all

I have a spreadsheet that has a list of cities in column AH. I would like
to make a macro that will read the value in the cell, compair it to the next
cell down and if the cities name is different then to insert two rows.

Thanks

Example
S Beloit
S Beloit
San Antonio
Sioux Falls
Sioux Falls

To become
S Beloit
S Beloit


San Antonio


Sioux Falls
Sioux Falls
 
P

Per Jessen

Hi

Try this:

Sub InsertRows()
StartRow = 2 'Headings in row 1
TargetCol = "AH"
EndRow = Cells(StartRow, TargetCol).End(xlDown).Row
r = EndRow

Do Until r = StartRow
If Cells(r, TargetCol).Value <> Cells(r - 1, TargetCol).Value Then
Rows(r).Insert
Rows(r).Insert
End If
r = r - 1
Loop
End Sub

Regards,
Per
 

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