Require Macro

Ron99

Active Member
Joined
Feb 10, 2010
Messages
347
Office Version
  1. 2016
Platform
  1. Windows
Hello,

I need a simple macro code for the below

In Column "L" I have "TRUE" & "FALSE" . I need a macro where it should insert a new row below every "TRUE" value.

Thanks,
Ron...
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Give this macro a try...
Code:
[table="width: 500"]
[tr]
	[td]Sub InsertRowAfterEachTrueInColumnL()
  Dim R As Long, LastRow As Long
  LastRow = Cells(Rows.Count, "L").End(xlUp).Row
  For R = LastRow To 2 Step -1
    If CBool(Cells(R - 1, "L").Value) = True Then Cells(R, "L").EntireRow.Insert
  Next
End Sub[/td]
[/tr]
[/table]
 
Upvote 0
If you're interested, here's a non looping approach ;)
Code:
Sub InsertRows()
   With Range("L2", Range("L" & Rows.Count).End(xlUp))
      .Replace False, "me", xlWhole, , , , False, False
      .SpecialCells(xlConstants, xlLogical).Offset(1).EntireRow.Insert
      .Replace "me", False
   End With
End Sub
 
Upvote 0
If you're interested, here's a non looping approach ;)
Code:
Sub InsertRows()
   With Range("L2", Range("L" & Rows.Count).End(xlUp))
      .Replace False, "me", xlWhole, , , , False, False
      .SpecialCells(xlConstants, xlLogical).Offset(1).EntireRow.Insert
      .Replace "me", False
   End With
End Sub
That code will not work correctly for multiple contiguous cells containing a TRUE value. To see this, put the following values in L1:L7 and run your code against it... all of the inserts will be applied to the first of the contiguous TRUE rows.

FALSE
FALSE
TRUE
TRUE
TRUE
TRUE
FALSE
 
Last edited:
Upvote 0
Excellent point Rick, hadn't noticed that.:(
 
Upvote 0

Forum statistics

Threads
1,223,249
Messages
6,171,031
Members
452,374
Latest member
keccles

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