VBA:Find a cell, insert a new row below and copy data into it

RonanH

New Member
Joined
May 9, 2011
Messages
6
Hi all

I have a large list of data that has missing entries.

I have started a macro to look for an "ERROR" entry (I have a simple if statement to insert ERROR if there is data missing) and insert a row below it. I would also like to delete the word ERROR.

But I am having trouble copying data into the new row.

There are 5 relevant colums:

A: This stays the same
B: This stays the same
C: If the number is divisble by 20, add 30 otherwise add 70
D: Inser the average of the number above and below the new row.

this is what I have so far.

Code:
Sub Macro4()
'
' Macro4 Macro
'
'
    Cells.Find(What:="ERROR", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
        xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
        , SearchFormat:=False).Activate
        ActiveCell.Delete
        ActiveCell.Offset(1).EntireRow.Insert
 
        ActiveCell.Offset(0, -4).Resize(1, 4).Copy
        With ActiveCell
            .PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
            SkipBlanks:=False, Transpose:=False
            .ClearOutline
        End With
End Sub

Many thanks,

Ro
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Forum statistics

Threads
1,224,552
Messages
6,179,484
Members
452,917
Latest member
MrsMSalt

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