LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
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 -




 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA to count rows from specific cell and insert rows Valerie Excel Programming 3 November 26th 07 10:14 PM
Insert rows: Formats & formulas extended to additonal rows Twishlist Excel Worksheet Functions 0 October 22nd 07 04:23 AM
Insert page breaks every 50 rows but do not include hidden rows Martin[_21_] Excel Programming 5 March 12th 07 05:10 PM
How do i insert of spacer rows between rows in large spreadsheets laurel Excel Discussion (Misc queries) 0 April 24th 06 01:38 PM
Copy Rows and insert these rows before a page break AQ Mahomed Excel Programming 0 June 8th 04 09:09 AM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"