+ Reply to Thread
Results 1 to 8 of 8

Need VBA code to copy row and insert copied rows

Hybrid View

clintazz Need VBA code to copy row and... 02-14-2018, 11:52 AM
Mumps1 Re: Need VBA code to copy row... 02-14-2018, 11:57 AM
clintazz Re: Need VBA code to copy row... 02-14-2018, 01:53 PM
Mumps1 Re: Need VBA code to copy row... 02-14-2018, 02:15 PM
clintazz Re: Need VBA code to copy row... 02-14-2018, 04:10 PM
Mumps1 Re: Need VBA code to copy row... 02-14-2018, 04:13 PM
clintazz Re: Need VBA code to copy row... 02-14-2018, 05:01 PM
Mumps1 Re: Need VBA code to copy row... 02-14-2018, 05:26 PM
  1. #1
    Registered User
    Join Date
    04-05-2017
    Location
    Malta
    MS-Off Ver
    Excel 2010
    Posts
    24

    Question Need VBA code to copy row and insert copied rows

    Hi all,

    I have zero experience in VBA, tried to google some solutions yet I can't nail this.

    I need to automate a simple process. I am copying rows (rows 127 to 138) then selecting row 143, right clicking and hitting 'insert copied cells'

    Can someone please provide me the code for this, i will be 'copying and pasting' this worksheet in the same file and would like this macro to work on the copied worksheets.

    Many thanks in advance.

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,097

    Re: Need VBA code to copy row and insert copied rows

    Try:
    Sub InsertRows()
        ActiveSheet.Rows("127:138").Copy
        ActiveSheet.Rows(143).Insert
        Application.CutCopyMode = False
    End Sub
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Registered User
    Join Date
    04-05-2017
    Location
    Malta
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Need VBA code to copy row and insert copied rows

    Hi there,

    Many thanks for your prompt reply. It sometimes work and other it doesn't


    I'm getting an error Run-time error 1004, copy method of class failed.

    I closed excel ran the macro and it ran, when i created a 'box' and assigned a macro to it, it gave me the same error again

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,097

    Re: Need VBA code to copy row and insert copied rows

    It is always easier to help and test possible solutions if we could work with your actual file. Can you attach a copy? Explain in detail what you are trying to do.

  5. #5
    Registered User
    Join Date
    04-05-2017
    Location
    Malta
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Need VBA code to copy row and insert copied rows

    This is going to be an extremely stupid question, how do i attached a file here?

  6. #6
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,097

    Re: Need VBA code to copy row and insert copied rows

    The only stupid question is the one you don't ask. Click the 'Go Advanced' button at the lower right. Then scroll down a bit and click 'Manage Attachments' and follow the instructions.

  7. #7
    Registered User
    Join Date
    04-05-2017
    Location
    Malta
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Need VBA code to copy row and insert copied rows

    I hope i followed the correct procedure,

    Case in point at first the code ran properly but then iwhen i deleted the created rows, it gave me an error. a couple of 'issues' the file is currently protected, password is clintazz. will we be able to do the macro in such a way that it unprotects the worksheet, copies and paste values the amounts in the new rows and then locks it again.
    Attached Files Attached Files

  8. #8
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,097

    Re: Need VBA code to copy row and insert copied rows

    I ran this macro, deleted the created rows and ran it again. I did this several times with no errors. Your used range went all the way to column ABX and down to row 836 even though all the extra columns and rows were blank. I deleted the unnecessary rows and columns.
    Sub InsertRows()
        ActiveSheet.Unprotect Password:="clintazz"
        ActiveSheet.Rows("127:139").Copy
        ActiveSheet.Rows(145).Insert
        Application.CutCopyMode = False
        ActiveSheet.Protect Password:="clintazz"
    End Sub
    Try the attached file.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Macro to Copy/Insert Copied cells based on user input # of rows/formatting rules
    By gaker10 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-04-2015, 11:42 AM
  2. [SOLVED] VBA to find, copy and insert mulitple copied rows (newbie)
    By RandiLee in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-17-2013, 10:26 AM
  3. Code for insert copied rows
    By Jiptastic in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-16-2013, 04:28 PM
  4. [SOLVED] insert rows COPIED
    By marreco in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-29-2012, 09:38 AM
  5. Open workbook, insert copied rows VBA code
    By VBA FTW in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-27-2012, 06:35 PM
  6. [SOLVED] Need help with copy rows and insert code...
    By MrFleming007 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-15-2009, 06:01 PM
  7. Can't Insert Copied Rows
    By Kent in forum Excel General
    Replies: 0
    Last Post: 04-07-2005, 06:54 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1