Results 1 to 9 of 9

Open workbook, insert copied rows VBA code

Threaded View

VBA FTW Open workbook, insert copied... 07-26-2012, 04:59 PM
xladept Re: Open workbook, insert... 07-26-2012, 06:32 PM
VBA FTW Re: Open workbook, insert... 07-26-2012, 06:55 PM
xladept Re: Open workbook, insert... 07-26-2012, 07:04 PM
VBA FTW Re: Open workbook, insert... 07-26-2012, 07:15 PM
xladept Re: Open workbook, insert... 07-26-2012, 07:18 PM
VBA FTW Re: Open workbook, insert... 07-27-2012, 05:23 PM
JosephP Re: Open workbook, insert... 07-26-2012, 07:23 PM
Cutter Re: Open workbook, insert... 07-27-2012, 06:35 PM
  1. #1
    Forum Contributor
    Join Date
    07-26-2012
    Location
    USA
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    351

    Open workbook, insert copied rows VBA code

    Hey everyone, this is my first post here, probably not my last I'm trying to write a simple macro to copy selected rows from one workbook and insert the copied rows into another workbook. The rows I need to select and copy will vary from day to day. Here's my code so far:

    Sub ContractorsTab()
        Workbooks.Open Filename:="X:\OSC DETAIL\Invoices Sent to AP\Sent Invoice Summary - 2012.xlsx"
        Selection.Copy
        Windows("Sent Invoice Summary - 2012.xlsx").Activate
        Sheets("Contractors").Select
        Rows("4:4").Select
        Selection.Insert Shift:=xlDown
        Windows("OS Invoices 07-15.xlsm").Activate
    End Sub
    My problem is the first line. Without it, this macro works fine if I already have the workbook I need to copy to open, but I'm trying to insert a little more code so the macro will automatically open up the workbook I'm inserting the copied rows to, then save and close. Obviously I haven't gotten to the save, close part yet, but I'm wondering if anyone could give me a little guidance on what is causing my error with the code above. The workbook opens fine with the above code, but then I get an error saying the "Selection.Insert Shift:=xlDown" line is not allowed because it is attempting to shift cells in a table on my worksheet. Why am I getting this error? The code worked flawlessly before I added the first line of code telling Excel to open my Sent Invoice Summary - 2012 workbook. Ever since adding in that piece of code, it isn't allowing the insert rows line to function. Anyone know what I'm missing or need to adjust? Thanks!

    -Eric
    Last edited by VBA FTW; 07-26-2012 at 06:30 PM.

Thread Information

Users Browsing this Thread

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

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