=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.
 

Some videos you may like

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

Joe4

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

Watch MrExcel Video

Forum statistics

Threads
1,113,859
Messages
5,544,700
Members
410,630
Latest member
Maggie28
Top