Insert blank row if condition met

FROGGER24

Well-known Member
Joined
May 22, 2004
Messages
704
Office Version
  1. 2013
  2. 2010
Platform
  1. Windows
As part of a macro I need to insert a blank row between the text of "L" and "D" looking in column "I" (variable length). The user wants to seperate all the "L" from all the "D" rows by have a blank row between the two.
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
I'm not sure I completely follow. Take a look at this. This assumes there is no header row. Column "I" looks like this:

L
D
D
L
D

Code:
Function InsertRows()
FindLastRow = Range("I100000").End(xlUp).Row
For x = FindLastRow To 2 Step -1
    TempValue = Range("I" & x - 1).Value
    If Range("I" & x).Value <> TempValue Then
        Rows(x & ":" & x).Select
        Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    End If
Next
End Function

The code would result in this:

L

D
D

L

D
 
Upvote 0
Thanks for the reply, the data will be sorted with all of the rows with a "D" at the top. I need to insert one row between the last d and the the first "L"
 
Upvote 0
So this function would handle this. It would take

D
D
L
L

and make it

D
D

L
L

The question is in cell "I" is there only a single character "D" and "L" or are you referring to words starting with "D" or "L" like

David
Doug
Larry
Lisa
 
Upvote 0
Rhino, your code worked great, I was having a senior moment and forgot to sort my data...
thank you for your help
 
Upvote 0

Forum statistics

Threads
1,224,595
Messages
6,179,798
Members
452,943
Latest member
Newbie4296

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top