+ Reply to Thread
Results 1 to 2 of 2

Target Cell location issue while copying entire sheet by Macro

  1. #1
    Registered User
    Join Date
    03-04-2016
    Location
    India
    MS-Off Ver
    2013
    Posts
    3

    Target Cell location issue while copying entire sheet by Macro

    I have a tool which multiple users have been running for quiet a long time. But last week suddenly few users started facing the issue with the error message "Run time error:1004 To paste all cells from an excel worksheet into the current worksheet, you must paste into the first cell (A1 or R1C1)"

    So the piece of code that is doing the action is given below


    Application.Calculation = xlCalculationManual
    Application.CalculateBeforeSave = True
    Range("CardiacLong_Contents").ClearContents
    Application.ScreenUpdating = False

    'Unprotect Process Sheet to insert important data
    Sheets("Process").Select
    ActiveSheet.Unprotect

    Dim wb As Workbook
    Dim wbOCLong As Workbook
    Dim ws, wsp As Worksheet
    Set wb = ActiveWorkbook
    Set ws = wb.Worksheets("Cardiac Long")
    Set wsp = wb.Worksheets("Process")
    MsgBox "Open Cardiac OC Long Term Report"
    Set wb = Workbooks.Open(Application.GetOpenFilename)
    'Warning if there are more than one sheets
    If (wb.Sheets.Count > 1) Then
    MsgBox "This HINAI report has two sheets. Please merge them manually and then upload them"
    End
    End If
    If (Columns.Count <= 256) Then
    MsgBox "Please save the input or uploading files as *.xlsx or *.xlsb and then upload them"
    End
    End If

    'Add the uploading file name as comment
    wsp.Range("C6").ClearComments
    wsp.Range("C6").AddComment wb.FullName

    'Clearing the timestamp to point out the possible error
    wsp.Range("TimeStamp_CardiacLong").ClearContents

    wb.Worksheets(1).Range("A1:XFD1048576").Copy
    ws.Range("A1").PasteSpecial xlPasteValues, xlPasteSpecialOperationNone, False, False


    The last two lines are copying from an entire sheet of a workbook and pasting into another sheet of a second workbook. The strange thing is although I am specifically written code to paste the data from cell A1, it is not doing so. It is trying to paste into the cell which was selected in the target sheet before running the macro. I couldn't replicate the issue in my system with the same office version although some of the users are constantly facing this.

    Has anyone faced this issue earlier? Can you please help?

  2. #2
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: Target Cell location issue while copying entire sheet by Macro

    I would say, this is your problem.
    Please Login or Register  to view this content.
    Now, wsp is pointing to the old file.

    Try changing object name of the second WB to WB2 and corresponding code.
    David
    (*) Reputation points appreciated.

+ 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. Copying rows from one sheet and adding it to sheet2 but each cell in a dif location
    By tdbandit in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-04-2016, 09:37 PM
  2. Macro issue with formula's not copying to the last cell
    By sx200n in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-02-2015, 07:58 AM
  3. VBA Macro - Copying entire row from selected cell (within a pre-defined range)
    By ginja in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-22-2014, 09:34 AM
  4. [SOLVED] Adjust a macro to check for content of a cell and then run a macro on target sheet
    By dreddster in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-17-2013, 04:37 AM
  5. VBA to target a charachter in a specific location in given cell and write it back out
    By Sparkplug90 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-10-2013, 06:32 PM
  6. Replies: 0
    Last Post: 04-06-2012, 05:07 PM
  7. Replies: 1
    Last Post: 02-19-2007, 04:52 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