+ Reply to Thread
Results 1 to 2 of 2

macro to copy cells to a new workbook doesn't work properly

  1. #1
    Registered User
    Join Date
    04-03-2009
    Location
    Gothenburg, Sweden
    MS-Off Ver
    Excel 2003
    Posts
    8

    macro to copy cells to a new workbook doesn't work properly

    I have this code:

    Sub export()
    Sheets("Sheet1").Range("Q2:AK2").Copy
    Workbooks.Open ("C:\Users\christians\Desktop\excel\test.xlsx")
    Sheets("Test").Activate
    Range("A1").Select
    Selection.End(xlDown).Select
    ActiveCell.Offset(1, 0).Select
    ActiveCell.PasteSpecial xlPasteAll
    Application.CutCopyMode = False
    End Sub

    Basicly I want to copy a range of cells to a new workbook. I want to paste the value of the cells on the first empty row. The code doen't work, I'm not sure but it seems like the code goes to the very last row of the workbook and then tries to paste the cells on nonexisting row under it. Can anyone please help me wit this?

  2. #2
    Valued Forum Contributor
    Join Date
    08-13-2012
    Location
    Gardony, Hungary
    MS-Off Ver
    Excel 2003
    Posts
    558

    Re: macro to copy cells to a new workbook doesn't work properly

    It probably fails because it goes to the last row and the tries to select the row after the last row, which obviously doesn't exist. You can try this altered code.
    Please Login or Register  to view this content.
    edit: also, please use code tags around your code to comply with forum rules.
    edit2: I love how you have a folder for Christian users. :P

+ 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.6.0 RC 1