+ Reply to Thread
Results 1 to 2 of 2

Thread: Close a work book and then paste to the bottom

  1. #1
    Registered User
    Join Date
    01-26-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    1

    Close a work book and then paste to the bottom

    Hi

    I am reletively new to VBA so sorry if this is simple!

    I have written some code which opens a work book and then pastes the data on to a tab. I am having difficulties in the next step, which is to close the work book i have opened without saving and i then need to do the same with another workbook and paste that in the next available row.

    The code I have so far is: the workbooks chnage everyweek so i have set this with the dim function, my problem is i dont know how to close a work book have for all of them, i have looked on line but i cant seem to get anything to work. so for each "wrk" i need it to close after it has pasted and i need to get the data from wrk3 pasted to the bottom of wrk2


    Dim wrk1 As String
    Dim wrk2 As String
    Dim wrk3 As String
    Dim wrk4 As String
    
    wrk1 = ThisWorkbook.Worksheets("Summary_Sheet").Range("D13").Value
    wrk2 = ThisWorkbook.Worksheets("Summary_Sheet").Range("D14").Value
    wrk3 = ThisWorkbook.Worksheets("Summary_Sheet").Range("D15").Value
    wrk4 = ThisWorkbook.Worksheets("Summary_Sheet").Range("D16").Value
    
    
    
    Workbooks.Open (wrk1), ReadOnly:=True
    Set wrk = Workbooks.Open(wrk1)
    wrk.Worksheets("Received Data").Range("1:7000").Copy ThisWorkbook.Worksheets("Received").Range("1:1")
    wrk.Worksheets("Closed Data").Range("1:7000").Copy ThisWorkbook.Worksheets("Cleared").Range("1:1")
    
    
    
    Workbooks.Open (wrk2), ReadOnly:=True
    Set wrk = Workbooks.Open(wrk2)
    wrk.Worksheets("ComplaintsData_Extract").Range("1:17000").Copy ThisWorkbook.Worksheets("Pending").Range("1:1")
    n = ThisWorkbook.Worksheets("Pending").Range("A:A").Cells.SpecialCells(xlCellTypeConstants).Count
    
    Workbooks.Open (wrk3), ReadOnly:=True
    Set wrk = Workbooks.Open(wrk3)
    wrk.Worksheets("ComplaintsData_Extract").Range("2:17000").Copy ThisWorkbook.Worksheets("Pending").Range("1:1")
    Last edited by Wortandy; 01-26-2012 at 05:41 AM.

  2. #2
    Forum Guru pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2010
    Posts
    5,155

    Re: Close a work book and then paste to the bottom

    Hi Wortandy
    unfortunately,
    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    regards pike

    If the solution helped please donate
    here to the RSPCA

    Sites worth visiting;

    J&R Solutions - royUK

    AJP Excel Information - Andy Pope

    Spreadsheet Toolbox

    VBA for smarties - snb

+ Reply to Thread

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