I just want to copy and insert rows

ouadad

Board Regular
Joined
Jun 19, 2005
Messages
213
The following code has worked before, but now it doesn't and I can't figure out why. I just determine the value in the activecell and if it's more than one I just copy the row and insert it below the selected row, but for some reason I get a runtime error 1004 and the insert method fails. I also note that the "i" in insert is not capitalized. Can anyone assist me?

Code:
Sub Deaggregate_returns()
' change multiple returns of same product to single returns
Dim qty As Integer, irow As Long, MyCell, step As Integer
Set MyCell = ActiveCell
While ActiveCell.Value <> ""
    qty = ActiveCell.Value
        For step = 1 To qty - 1
            Rows(ActiveCell.Row).Select
            Selection.Copy
            Selection.insert Shift:=xlDown
        Next step
        MyCell.Offset(1, 0).Select
        Set MyCell = ActiveCell
Wend
End Sub
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
It is possible that your code module has become corrupted.

Try the following.


Copy all of the code in your module into notepad
Right click on the module
Select Remove <module name> from the dropdown
Right click on the project name
select insert => Module
Copy your code back into the new module
 
Upvote 0
It is possible that your code module has become corrupted.

Try the following.


Copy all of the code in your module into notepad
Right click on the module
Select Remove <module name> from the dropdown
Right click on the project name
select insert => Module
Copy your code back into the new module


No, that didn't solve the problem. ... But restarting my computer did. Go figure.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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