Insert new row vba

Lorlai

Board Regular
Joined
May 26, 2011
Messages
85
I have a sheet full of data copied from a table. I have a macro running that is adding a blank row if certain criteria is met. However, instead of a whole row being inserted, only a cell is inserted. How can I get it to insert a row?

Column A Column B Column C Column D Column E Column F Column G
1234555 1234566 1234577 1234588 1234599 1234500 1234655
2234555 2234566 2234577 2234588 2234599 BLANK 2234655
3234555 3234566 3234577 3234588 3234599 2234500 3234655


This is what it is doing. Inserting a blank cell, then pushing that value below. I want it to do this:
Column A Column B Column C Column D Column E Column F Column G
1234555 1234566 1234577 1234588 1234599 1234500 1234655
BLANK ROW INSERTED HERE
2234555 2234566 2234577 2234588 2234599 2234500 2234655
3234555 3234566 3234577 3234588 3234599 3234500 3234655


Is there a way to do this? My code that is inserting a blank cell is below:

Code:
Do
Sheets("P").Select
PValue = ActiveCell.Value
Sheets("C").Select
CValue = ActiveCell.Value
If PValue <> CValue Then
    If PValue > CValue Then
    Sheets("P").Select
    Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    End If

    If CValue > PValue Then
    Sheets("C").Select
    Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    End If
    
    If IsEmpty(PValue) And IsEmpty(CValue) Then
    Exit Sub
    End If
End If

Sheets("P").Select
ActiveCell.Offset(1, 0).Select

Sheets("C").Select
ActiveCell.Offset(1, 0).Select

 
Loop Until IsEmpty(ActiveCell)

Thank you!!
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Try (twice)

Code:
Selection.EntireRow.Insert CopyOrigin:=xlFormatFromLeftOrAbove
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,834
Members
452,947
Latest member
Gerry_F

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