=IF MACRO

Royston31

Board Regular
Joined
Jul 23, 2006
Messages
182
Could anyone tell me how to write this macro?

if the value of any cell in a specifide colonm is 30. then i need it to insert a row below then copy & paste the data from the '30' row into it.

Sure it will be will be easy for you guy's, however im a bit of an amature!!

Kind Regards,

Roy.
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
58,912
Office Version
  1. 365
Platform
  1. Windows
This is written for column A. Simply change all the "A"s to the appropraite column:
Code:
Sub MyCopy()

    Dim i As Long
    For i = Range("A65536").End(xlUp).Row To 1 Step -1
        If Cells(i, "A") = 30 Then
            Rows(i + 1).EntireRow.Insert
            Rows(i).Copy
            Cells(i + 1, "A").Select
            ActiveSheet.Paste
            Application.CutCopyMode = False
        End If
    Next i
    
End Sub
 

Royston31

Board Regular
Joined
Jul 23, 2006
Messages
182
Cheers jm,

How would i then change it to just copy & paste a range from the row say....A1:P1?
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
58,912
Office Version
  1. 365
Platform
  1. Windows
Change
Rows(i).Copy
to
Range(Cells(i, "A"), Cells(i, "P")).Copy
 

Forum statistics

Threads
1,140,937
Messages
5,703,256
Members
421,289
Latest member
fbohlandt

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