Macro to insert row

mewalker0

New Member
Joined
Jan 24, 2005
Messages
22
Need to find a macro that will check the value "DATE" of a cell and insert a row if the cell below it is greater.
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

tactps

Well-known Member
Joined
Jan 20, 2004
Messages
3,460
Sub macro()
If ActiveCell.Value < ActiveCell.Offset(1, 0).Value Then ActiveCell.Offset(1, 0).EntireRow.Insert
End Sub

You will need to add in some sort of loop to keep it running, eg:
Sub macro()
counter = 1
do until counter = 500
If ActiveCell.Value < ActiveCell.Offset(1, 0).Value Then ActiveCell.Offset(1, 0).EntireRow.Insert
if activecell.offset(1,0).text = "" then activecell.offset(1,0).select
activecell.offset(1,0).select
counter = counter + 1
loop
End Sub
 

Smitty

Legend
Joined
May 15, 2003
Messages
29,536
Welcome to the Board!

How about this:

<font face=Tahoma><SPAN style="color:#00007F">Sub</SPAN> InsertRow()
    <SPAN style="color:#00007F">If</SPAN> ActiveCell.Offset(1, 0).Value > ActiveCell.Value <SPAN style="color:#00007F">Then</SPAN> ActiveCell.Offset(1, 0).EntireRow.Insert
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

Hope that helps,

Smitty
 

tactps

Well-known Member
Joined
Jan 20, 2004
Messages
3,460
Looks a lot like mine, Smitty (lol) - Beat you again! Hope you are well.
 

mewalker0

New Member
Joined
Jan 24, 2005
Messages
22
That works great but what would I have to change to make it look at a range in a collumn instead of starting on the active cell? Looking for a way to add this , run the macro and have if just look within a range.
 

Forum statistics

Threads
1,147,688
Messages
5,742,627
Members
423,744
Latest member
bkirtland

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
Top