+ Reply to Thread
Results 1 to 4 of 4

Can't Bypass error Copy area and CopyPaste are not the same

Hybrid View

lougs7 Can't Bypass error Copy area... 10-06-2015, 04:59 PM
protonLeah Re: Can't Bypass error Copy... 10-06-2015, 08:08 PM
lougs7 Re: Can't Bypass error Copy... 10-07-2015, 09:49 AM
protonLeah Re: Can't Bypass error Copy... 10-09-2015, 09:48 PM
  1. #1
    Forum Contributor
    Join Date
    09-23-2015
    Location
    Toronto, Ontario
    MS-Off Ver
    Excel 2010
    Posts
    187

    Can't Bypass error Copy area and CopyPaste are not the same

    MainFile.xlsmDataSource.xls

    Hi guys,

    I wrote code to copy data from one workbook that is closed and I need to paste it on the next available blank row in the workbook I am working in called "dashboard Shell1", but I keep getting the error message "The information cannot be pasted because the copy area and the copy paste area are not the same size" This is because the sheet I am working on where the data will be pasted is using merged cells (need to stay merge) [view image]
    002- DASHBOARD.PNG


    the data come from one Column in this sheet...
    002- DATASHEET.PNG

    here's the code I used, the error I mention comes in at the pasting part

     
    
    Public Sub RetrieveData()
    
        'Retrieves Range A2:A100 from DHR Report and pastes it in Specified Range on Dashboard
        
        Dim wbDash              As Workbook 'workbook where the data is to be pasted
        Dim wbData              As Workbook 'workbook from where the data is to copied
        
        'take off alerts to avoid Save As pop up
        Application.ScreenUpdating = False
        
        Set wbDash = ActiveWorkbook  'Dashboard
        Set wbData = Workbooks.Open("C:\Users\673157897\Documents\Pro Fees Dash Board\Copy of RBC_CWM_DHR_Details_Report___Thomson__A (Preview).xls")
        
            'select cell A1 on the target book
                wbData.Sheets("Sheet1").Range("A2:A100").Copy
            'paste the data on the Dashboard book
               
    Dim lst As Long
    lst = wbDash.Sheets("Data").Range("A" & Rows.Count).End(xlUp).Row + 1
    
    wbDash.Sheets("Data").Range("A" & lst).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                :=False, Transpose:=False
           
            'clear any thing on clipboard to maximize available memory
                Application.CutCopyMode = False
            'takes off alerts
                Application.DisplayAlerts = False
            'close the data book
                wbData.Close
            'activate the Dashboard file
                wbDash.Activate
          
                Application.DisplayAlerts = True
                Application.ScreenUpdating = True
        
    End Sub

    Please help someone!! Please
    Last edited by lougs7; 10-07-2015 at 09:48 AM.

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,933

    Re: Can't Bypass error Copy area and CopyPaste are not the same

    From the picture, none of those merged cells is necessary unless there is something to the far right side that you did not show us. You adjust the row height/width by using the cell format menu or just drag the row header separator bar on the left down as desired. My suggestion is to unmerge those cells, delete the empty rows and re-adjust the row height 'til it looks pretty. Merged cell on worksheets are always trouble.
    Ben Van Johnson

  3. #3
    Forum Contributor
    Join Date
    09-23-2015
    Location
    Toronto, Ontario
    MS-Off Ver
    Excel 2010
    Posts
    187

    Re: Can't Bypass error Copy area and CopyPaste are not the same

    Hi Ben, I edited my post to attach the files, I changed their names and info with ficticious stuff [for the file path put C:\filepath, ill put it inmyself]. Maybe you can help me write code for this, or suggest another way to do in code it not dealing with merged cells.

  4. #4
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,933

    Re: Can't Bypass error Copy area and CopyPaste are not the same

    Try this one:
    Option Explicit
    Public Sub RetrieveData()
        'Retrieves Range A2:A100 from DHR Report and pastes it in Specified Range on Dashboard
        Dim SOURCE          As Workbook 'workbook from where the data is to copied from
        Dim SrcSheet        As Worksheet
        Dim DESTINATION     As Worksheet 'workbook where the data is to be pasted to
        Dim NextRow         As Long
        Dim ContractorCount As Long
        Dim SourceArray()   As Variant
        Dim Contractor      As Variant
        
        'take off alerts to avoid Save As pop up
        Application.ScreenUpdating = False
        
        Set DESTINATION = ThisWorkbook.Sheets("destination")      'Dashboard
        NextRow = DESTINATION.Range("A1").CurrentRegion.Rows.Count + 1
        
        Set SOURCE = Workbooks.Open("C:\DOWNLOADS.NEW\DataSource(lougs7).xls")
        Set SrcSheet = SOURCE.Sheets("source data")
        ContractorCount = SrcSheet.Cells(Rows.Count, 1).End(xlUp).Row - 4
        
        'copy the contactor names to an array and close the source file without saving
        SourceArray = SrcSheet.Range("A5").Resize(rowsize:=ContractorCount).Value
        SOURCE.Close False
        
        For Each Contractor In SourceArray
            DESTINATION.Cells(NextRow, 1).Value = Contractor
            
            'copy the merged cell formats and paste to the last cell
            DESTINATION.Cells(NextRow, 1).Offset(-5).Resize(5).Copy
            DESTINATION.Cells(NextRow, 1).PasteSpecial Paste:=xlPasteFormats
            NextRow = NextRow + 5   ' 5 merged cells
        Next Contractor
        
        Application.DisplayAlerts = True
        Application.ScreenUpdating = True
    End Sub

+ 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. Bypass missing reference VBA error
    By lamarao in forum Excel Programming / VBA / Macros
    Replies: 25
    Last Post: 11-10-2018, 02:45 AM
  2. Replies: 3
    Last Post: 02-23-2015, 06:51 AM
  3. [SOLVED] DropBox value triggering copypaste by "SEARCHING" for the correct cells to copypaste
    By tnuis in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-03-2013, 09:41 AM
  4. [SOLVED] copy values from current area to other area using indirect addressing
    By Algirdas in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-30-2012, 04:33 AM
  5. Error Generation during copypaste macro run
    By ravinder_tigh in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-26-2009, 01:00 AM
  6. Bypass the run time error if user enters a wrong value
    By Richard Flame in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-30-2007, 11:26 AM
  7. [SOLVED] Optimization question: how to bypass copy and paste
    By samer.kurdi@gmail.com in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-10-2005, 04:05 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