Thread: Insert Rows
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
[email protected] marc747@excite.com is offline
external usenet poster
 
Posts: 55
Default Insert Rows

Hi,
Thanks, Its works but a few small issue. It will be great if you can
look at the Macro and see if I looks correct.
1)The Columns now are "HB" and "HC"
2)When I run the Macro it inserts Rows below the Header, It should
start inserting from Row2.
3) How would I adjust number of rows to insert.


Sub InsrtRw()
Dim lr As Long
Dim Rng1 As Range
lr = Cells(Rows.Count, 3).End(xlUp).Row
Set Rng1 = Range("HB2:C" & lr)
For i = lr To 2 Step -1
If (Range("HB" & i) < Range("HB" & i - 1)) Then
Range("HB" & i & ":C" & i + 1).EntireRow.Insert

End If

If (Range("HC" & i) < Range("HC" & i - 1)) Then
Range("HC" & i & ":C" & i + 1).EntireRow.Insert

End If
Next
End Sub

--------------------------------------------------------------------------



On Aug 6, 4:30*pm, JLGWhiz wrote:
That would still put two blank rows in one column or the other at a point
that is not a value change. *But if that does not matter to the OP, then it
is a time saver.



"J Sedoff" wrote:
For the line:
If Range("C" & i) < Range("C" & i - 1) Then


Change it to:
If (Range("C" & i) < Range("C" & i - 1)) or (Range("D" & i) < Range("D" & i - 1)) Then


That will add your rows if either Column C or D have different values than
their next row. *That'll work for you if you don't want four blank rows when
you have different values for BOTH C and D in the next rows.


Hope this helps, Jim
--
I appreciate any feedback. *Please don''t be scared to say that "Yes"
I/someone else did answer your question. *Thank you.


"JLGWhiz" wrote:


The first column is easy:


Sub InsrtRw()
* *Dim lr As Long
* *Dim Rng1 As Range
* *lr = Cells(Rows.Count, 3).End(xlUp).Row
* *Set Rng1 = Range("C1:C" & lr)
* *For i = lr To 2 Step -1
* * * If Range("C" & i) < Range("C" & i - 1) Then
* * * * *Range("C" & i & ":C" & i + 1).EntireRow.Insert
* * * End If
* *Next
End Sub- Hide quoted text -


- Show quoted text -