Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Code To Insert Blank Rows

I have a file with a listing of entries, and in column B of all the entries,
are unique names. I need to create the code to reference the listing, which
at times will be 200 entries and other times 1000 entries, and evaluate the
data in column B, to then insert 2 blank rows every time a different name
appears. For instance

Initially column B has
(Row 1) Pears
(2) Pears
(3) Pears
(4) Apples
(5) Grapes
(6) Grapes

After the desired code, the results would be..
(Row 1) Pears
(2) Pears
(3) Pears
(4) Blank Row
(5) Blank Row
(6) Apples
(7) Blank Row
(8) Blank Row
(9) Grapes
(10) Grapes
END OF FILE

Any and all help will be appreciated - Thank You In Advance
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,533
Default Code To Insert Blank Rows

Try this which will ignore previously inserted blank rows:

Sub InsertRows()
Dim LastRow As Long
Dim CheckValue As String

LastRow = Range("B" & Rows.Count).End(xlUp).Row
CheckValue = Range("B" & LastRow).Value

For r = LastRow To 1 Step -1
If CheckValue < Range("B" & r) And Range("B" & r) < "" Then
CheckValue = Range("B" & r).Value
Range("B" & r + 1).Resize(2).EntireRow.Insert
End If
Next
End Sub


Regards,
Per

"MWS-C360" skrev i meddelelsen
...
I have a file with a listing of entries, and in column B of all the
entries,
are unique names. I need to create the code to reference the listing,
which
at times will be 200 entries and other times 1000 entries, and evaluate
the
data in column B, to then insert 2 blank rows every time a different name
appears. For instance

Initially column B has
(Row 1) Pears
(2) Pears
(3) Pears
(4) Apples
(5) Grapes
(6) Grapes

After the desired code, the results would be..
(Row 1) Pears
(2) Pears
(3) Pears
(4) Blank Row
(5) Blank Row
(6) Apples
(7) Blank Row
(8) Blank Row
(9) Grapes
(10) Grapes
END OF FILE

Any and all help will be appreciated - Thank You In Advance


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Code To Insert Blank Rows

Try the below macro

Sub Macro()
Dim lngRow As Long
For lngRow = Cells(Rows.Count, "A").End(xlUp).Row To 2 Step -1
If Range("A" & lngRow) < Range("A" & lngRow - 1) Then
Rows(lngRow).EntireRow.Resize(2).Insert
End If
Next
End Sub

--
Jacob


"MWS-C360" wrote:

I have a file with a listing of entries, and in column B of all the entries,
are unique names. I need to create the code to reference the listing, which
at times will be 200 entries and other times 1000 entries, and evaluate the
data in column B, to then insert 2 blank rows every time a different name
appears. For instance

Initially column B has
(Row 1) Pears
(2) Pears
(3) Pears
(4) Apples
(5) Grapes
(6) Grapes

After the desired code, the results would be..
(Row 1) Pears
(2) Pears
(3) Pears
(4) Blank Row
(5) Blank Row
(6) Apples
(7) Blank Row
(8) Blank Row
(9) Grapes
(10) Grapes
END OF FILE

Any and all help will be appreciated - Thank You In Advance

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Code To Insert Blank Rows

This worked perfectly!!!!

Thank You - I really appreciate your assistance!!!!

"Jacob Skaria" wrote:

Try the below macro

Sub Macro()
Dim lngRow As Long
For lngRow = Cells(Rows.Count, "A").End(xlUp).Row To 2 Step -1
If Range("A" & lngRow) < Range("A" & lngRow - 1) Then
Rows(lngRow).EntireRow.Resize(2).Insert
End If
Next
End Sub

--
Jacob


"MWS-C360" wrote:

I have a file with a listing of entries, and in column B of all the entries,
are unique names. I need to create the code to reference the listing, which
at times will be 200 entries and other times 1000 entries, and evaluate the
data in column B, to then insert 2 blank rows every time a different name
appears. For instance

Initially column B has
(Row 1) Pears
(2) Pears
(3) Pears
(4) Apples
(5) Grapes
(6) Grapes

After the desired code, the results would be..
(Row 1) Pears
(2) Pears
(3) Pears
(4) Blank Row
(5) Blank Row
(6) Apples
(7) Blank Row
(8) Blank Row
(9) Grapes
(10) Grapes
END OF FILE

Any and all help will be appreciated - Thank You In Advance

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Code To Insert Blank Rows

Rows(lngRow).EntireRow.Resize(2).Insert

Since you used the Rows object in the above line from your posted code, you
don't need to specify the EntireRow property... this should work the same
way...

Rows(lngRow).Resize(2).Insert

--
Rick (MVP - Excel)


"Jacob Skaria" wrote in message
...
Try the below macro

Sub Macro()
Dim lngRow As Long
For lngRow = Cells(Rows.Count, "A").End(xlUp).Row To 2 Step -1
If Range("A" & lngRow) < Range("A" & lngRow - 1) Then
Rows(lngRow).EntireRow.Resize(2).Insert
End If
Next
End Sub

--
Jacob


"MWS-C360" wrote:

I have a file with a listing of entries, and in column B of all the
entries,
are unique names. I need to create the code to reference the listing,
which
at times will be 200 entries and other times 1000 entries, and evaluate
the
data in column B, to then insert 2 blank rows every time a different name
appears. For instance

Initially column B has
(Row 1) Pears
(2) Pears
(3) Pears
(4) Apples
(5) Grapes
(6) Grapes

After the desired code, the results would be..
(Row 1) Pears
(2) Pears
(3) Pears
(4) Blank Row
(5) Blank Row
(6) Apples
(7) Blank Row
(8) Blank Row
(9) Grapes
(10) Grapes
END OF FILE

Any and all help will be appreciated - Thank You In Advance




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Code To Insert Blank Rows

Range("B" & r + 1).Resize(2).EntireRow.Insert

For the above line from your posted code, you could use Rows instead of
Range and do away with the call to the EntireRow property...

Rows(r + 1).Resize(2).Insert

--
Rick (MVP - Excel)


"Per Jessen" wrote in message
...
Try this which will ignore previously inserted blank rows:

Sub InsertRows()
Dim LastRow As Long
Dim CheckValue As String

LastRow = Range("B" & Rows.Count).End(xlUp).Row
CheckValue = Range("B" & LastRow).Value

For r = LastRow To 1 Step -1
If CheckValue < Range("B" & r) And Range("B" & r) < "" Then
CheckValue = Range("B" & r).Value
Range("B" & r + 1).Resize(2).EntireRow.Insert
End If
Next
End Sub


Regards,
Per

"MWS-C360" skrev i meddelelsen
...
I have a file with a listing of entries, and in column B of all the
entries,
are unique names. I need to create the code to reference the listing,
which
at times will be 200 entries and other times 1000 entries, and evaluate
the
data in column B, to then insert 2 blank rows every time a different name
appears. For instance

Initially column B has
(Row 1) Pears
(2) Pears
(3) Pears
(4) Apples
(5) Grapes
(6) Grapes

After the desired code, the results would be..
(Row 1) Pears
(2) Pears
(3) Pears
(4) Blank Row
(5) Blank Row
(6) Apples
(7) Blank Row
(8) Blank Row
(9) Grapes
(10) Grapes
END OF FILE

Any and all help will be appreciated - Thank You In Advance



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Code To Insert Blank Rows

Yes Rick. I initially wrote that as Range() and later changed that to
Rows()...missed to remove that. Thanks for pointing that out..

--
Jacob


"Rick Rothstein" wrote:

Rows(lngRow).EntireRow.Resize(2).Insert


Since you used the Rows object in the above line from your posted code, you
don't need to specify the EntireRow property... this should work the same
way...

Rows(lngRow).Resize(2).Insert

--
Rick (MVP - Excel)


"Jacob Skaria" wrote in message
...
Try the below macro

Sub Macro()
Dim lngRow As Long
For lngRow = Cells(Rows.Count, "A").End(xlUp).Row To 2 Step -1
If Range("A" & lngRow) < Range("A" & lngRow - 1) Then
Rows(lngRow).EntireRow.Resize(2).Insert
End If
Next
End Sub

--
Jacob


"MWS-C360" wrote:

I have a file with a listing of entries, and in column B of all the
entries,
are unique names. I need to create the code to reference the listing,
which
at times will be 200 entries and other times 1000 entries, and evaluate
the
data in column B, to then insert 2 blank rows every time a different name
appears. For instance

Initially column B has
(Row 1) Pears
(2) Pears
(3) Pears
(4) Apples
(5) Grapes
(6) Grapes

After the desired code, the results would be..
(Row 1) Pears
(2) Pears
(3) Pears
(4) Blank Row
(5) Blank Row
(6) Apples
(7) Blank Row
(8) Blank Row
(9) Grapes
(10) Grapes
END OF FILE

Any and all help will be appreciated - Thank You In Advance


.

Reply
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
Text to Rows and then Insert Blank Rows [email protected] Excel Discussion (Misc queries) 1 December 20th 08 04:23 PM
How do i insert blank rows between data that is thousands of rows paul.eatwell Excel Discussion (Misc queries) 5 April 14th 08 10:49 PM
insert blank rows sillyscorpio Excel Discussion (Misc queries) 2 December 7th 07 03:23 PM
How do I insert blank rows between rows in completed worksheet? bblue1978 Excel Discussion (Misc queries) 1 October 26th 06 07:02 PM
Macro code to test for blank row and insert blank row if false Mattie Excel Programming 2 March 29th 06 01:19 AM


All times are GMT +1. The time now is 01:27 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"