Results 1 to 3 of 3

Thread: I just want to copy and insert rows

  1. #1
    Board Regular
    Join Date
    Jun 2005
    Posts
    195
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default I just want to copy and insert rows

    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

  2. #2
    Board Regular
    Join Date
    Feb 2006
    Location
    NJ, USA
    Posts
    331
    Post Thanks / Like
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Default Re: I just want to copy and insert rows

    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 from the dropdown
    Right click on the project name
    select insert => Module
    Copy your code back into the new module
    - Posting guidelines, forum rules and terms of use

    - Try searching for your answer first, see how

    - Read the FAQs

    - List of BB codes

    Also, when asking questions, please be as detailed as possible, and If I have helped you, please let me know.
    I don't require thanks, but acknowledgement is nice

  3. #3
    Board Regular
    Join Date
    Jun 2005
    Posts
    195
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: I just want to copy and insert rows

    Quote Originally Posted by Richard U View Post
    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 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 by ouadad; Jun 20th, 2019 at 01:37 PM.

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •