VBA code to insert rows in table
Public Sub ProcessData()
Dim iLastRow As Long
Dim i As Long
With ActiveSheet
iLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = iLastRow To 2 Step -1
If .Cells(i, "A").Value < .Cells(i - 1, "A") Then
.Rows(i).Insert
.Cells(i, "B").Value = .Cells(i + 1, "A").Value
End If
Next i
.Rows(1).Insert
.Cells(1, "B").Value = .Cells(2, "A").Value
End With
End Sub
--
---
HTH
Bob
(there's no email, no snail mail, but somewhere should be gmail in my addy)
"Tevuna" wrote in message
...
I have a table (list) of property addresses sorted by location, which is
the
left-most column in the table. Sometimes, locations happen to be rather
long.
To save space on the printed copy, I would like to set the locations
column
out of the print range, and, in order to break the table according to
locations, insert a new table row just above any row which starts a new
location.
I'm in need for good VBA code which will 1) scan the Locations column, top
to bottom, for a change in location, and when such a change is detected 2)
insert a new table row just above that row 3) Copy the new location text
and
4) paste it one row above and one column to the right from the copied
cell.
Could any one please help me with this code?
|