Macro - Find Next Change In A Column; then insert row
this may be one way, assuming the data starts in row2 of column A
Sub test()
Dim ws As Worksheet
Dim i As Long
Dim lastrow As Long
Set ws = Worksheets("sheet1")
lastrow = ws.Cells(Rows.Count, "A").End(xlUp).Row
For i = lastrow To 2 Step -1
With ws
If .Range("A" & i) < .Range("A" & i - 1) Then
.Range("A" & i).EntireRow.Insert
End If
End With
Next
End Sub
--
Gary
"masterbaker" wrote in message
...
This has to be possible and someone knows how to do it: I need a Macro that
will scan down a column and insert a row before the next change in values.
It's essentially similar to the subtotal function where you select "at each
change in:" but I need a way to break up tons of data sorted within a column
but the values are not static.
Sample Data:
Column A Column B
apple 25
apple 30
grape 26
grape 28
cherry 24
pear 27
Without knowing the actual values in column A, I need a macro that will
insert a row between apple/grape and then grape/cherry and then cherry/pear
and so on down the worksheet. I have tried a macro that uses the find
function, but I have to know what the values in column A are going to be,
which I don't.
This would be HUGE if possible. Please help!
|