+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    03-20-2010
    Location
    Wales
    MS-Off Ver
    Excel 2003, 2007 and 2010
    Posts
    1

    Macro to copy non adjacent cells to external workbook and move down row

    I currently use 2003, 2007 and 2010 versions of Excel, and do know how to record and run a macro, though I do not write VB. I have an invoice template which I bring in, fill in individual details using data validation/drop down boxes) and print off. I then want to be able to copy, for instance, data in cells c21, c12, e18, and g59 (in that order) to an external workbook in a row format so that at end of each month I have date, name, ref and total in tabular format. I can easily write the macro copying the data over to the other workbook but can't get it to move down one line so that when I copy a subsequent invoice data over, it doesn't overwrite what was previously pasted. I would appreciate any help.

  2. #2
    Forum Guru mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2007/2010
    Posts
    2,815

    Re: Macro to copy non adjacent cells to external workbook and move down row

    Try this adjusting the names of the sheets/workbooks in the first three lines as appropriate.

    Code:
    Sub CopySpecial()
    Const SourceSheet = "Invoice template"
    Const TargetSheet = "Tabular view"
    Const ExternalWorkbook = "My external workbook.xls"
    
    Sheets(SourceSheet).Range("$C$21").Copy Destination:=Workbooks(ExternalWorkbook).Sheets(TargetSheet).Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
    Sheets(SourceSheet).Range("$C$12").Copy Destination:=Workbooks(ExternalWorkbook).Sheets(TargetSheet).Cells(Rows.Count, 1).End(xlUp).Offset(0, 1)
    Sheets(SourceSheet).Range("$E$18").Copy Destination:=Workbooks(ExternalWorkbook).Sheets(TargetSheet).Cells(Rows.Count, 1).End(xlUp).Offset(0, 2)
    Sheets(SourceSheet).Range("$G$59").Copy Destination:=Workbooks(ExternalWorkbook).Sheets(TargetSheet).Cells(Rows.Count, 1).End(xlUp).Offset(0, 3)
    
    End Sub
    The workbook containing the invoice template needs to be active and the external workbook open.
    Martin

    Eighty Twenty Spreadsheet Automation http://homepage.ntlworld.com/martin.rice1/ for all your Excel customisation and consulting needs.

    If my solution has saved you time and/or money, please consider donating to Cancer Research UK.

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