=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

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
65,556
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
65,556
Office Version
  1. 365
Platform
  1. Windows
Change
Rows(i).Copy
to
Range(Cells(i, "A"), Cells(i, "P")).Copy
 

Forum statistics

Threads
1,176,486
Messages
5,903,354
Members
435,020
Latest member
rustyesimpson

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