ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Inserting Row after data change (https://www.excelbanter.com/excel-programming/418572-inserting-row-after-data-change.html)

ATanker62

Inserting Row after data change
 
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





Per Jessen

Inserting Row after data change
 
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

"ATanker62" skrev i meddelelsen
...
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







All times are GMT +1. The time now is 12:05 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com