+ Reply to Thread
Results 1 to 9 of 9

copy paste error to another sheet

Hybrid View

nuraisyah copy paste error to another... 04-11-2016, 10:09 PM
AlphaFrog Re: copy paste error to... 04-11-2016, 11:43 PM
nuraisyah Re: copy paste error to... 04-11-2016, 11:54 PM
AlphaFrog Re: copy paste error to... 04-11-2016, 11:56 PM
nuraisyah Re: copy paste error to... 04-11-2016, 11:58 PM
AlphaFrog Re: copy paste error to... 04-12-2016, 12:22 AM
nuraisyah Re: copy paste error to... 04-12-2016, 06:07 AM
AlphaFrog Re: copy paste error to... 04-12-2016, 11:07 AM
nuraisyah Re: copy paste error to... 04-12-2016, 09:36 PM
  1. #1
    Registered User
    Join Date
    04-06-2016
    Location
    malaysia
    MS-Off Ver
    MS office 2013
    Posts
    12

    Unhappy copy paste error to another sheet

    Hi,

    How should i adjust the coding, so that the info in the column below will be replaced at the same place each time data updated?
    when i update the data in sheet 1 and re-run the macro, the details (in another sheet) will be updated from line 20 onwards. By right, it should be replaced on the same row, that is from row 4 to 19.
    I think my copy paste coding is not right. Below are the codings:
    Dim lastrow As Long, erow As Long
    
    lastrow = Sheets("PO Tracking Details").Cells(Rows.Count, 2).End(xlUp).Row
    For i = 7 To lastrow
        Sheets("PO Tracking Details").Cells(i, 2).Copy
        erow = Sheets("PO Summary").Cells(Rows.Count, 2).End(xlUp).Offset(1, 0).Row
    
        Worksheets("PO Summary").Cells(erow, 2).Value = Sheets("PO Tracking Details").Cells(i, 2).Value
        Worksheets("PO Summary").Cells(erow, 3).Value = Sheets("PO Tracking Details").Cells(i, 3).Value
        Worksheets("PO Summary").Cells(erow, 4).Value = Sheets("PO Tracking Details").Cells(i, 4).Value
        Worksheets("PO Summary").Cells(erow, 5).Value = Sheets("PO Tracking Details").Cells(i, 5).Value
        Worksheets("PO Summary").Cells(erow, 6).Value = Sheets("PO Tracking Details").Cells(i, 6).Value
        Worksheets("PO Summary").Cells(erow, 7).Value = Sheets("PO Tracking Details").Cells(i, 10).Value
    
    Next i
    
    End Sub

    snapshot 1.jpg
    Last edited by JBeaucaire; 04-11-2016 at 10:57 PM. Reason: Added missing CODE tags. Please read and follow the Forum Rules, link above in the menu bar. Thanks.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: copy paste error to another sheet

        Dim lastrow As Long, erow As Long
        
        lastrow = Sheets("PO Tracking Details").Cells(Rows.Count, 2).End(xlUp).Row
        erow = 4
        
        For i = 7 To lastrow
        
            Worksheets("PO Summary").Cells(erow, 2).Resize(, 5).Value = _
                Sheets("PO Tracking Details").Cells(i, 2).Resize(, 5).Value
                
            Worksheets("PO Summary").Cells(erow, 7).Value = _
                Sheets("PO Tracking Details").Cells(i, 10).Value
                
            erow = erow + 1
            
        Next i
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    04-06-2016
    Location
    malaysia
    MS-Off Ver
    MS office 2013
    Posts
    12

    Re: copy paste error to another sheet

    Hi,

    it didnt work. i think because of the "Resize"

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: copy paste error to another sheet

    Quote Originally Posted by nuraisyah View Post
    Hi,

    it didnt work. i think because of the "Resize"
    What happened?

  5. #5
    Registered User
    Join Date
    04-06-2016
    Location
    malaysia
    MS-Off Ver
    MS office 2013
    Posts
    12

    Re: copy paste error to another sheet

    When i click F8, there's a pop up that needs me to debug and edit.

    it is at the (_) value below:

    Worksheets("PO Summary").Cells(erow, 2).Resize(, 5).Value = _
    Sheets("PO Tracking Details").Cells(i, 2).Resize(, 5).Value

    Worksheets("PO Summary").Cells(erow, 7).Value = _
    Sheets("PO Tracking Details").Cells(i, 10).Value

  6. #6
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: copy paste error to another sheet

    It worked for me.
    The .Resize syntax is correct.
    Did you copy\paste the code as is or did you type in the new code?
    Did you make any changes to the code?
    What is the error description?

  7. #7
    Registered User
    Join Date
    04-06-2016
    Location
    malaysia
    MS-Off Ver
    MS office 2013
    Posts
    12

    Re: copy paste error to another sheet

    Quote Originally Posted by AlphaFrog View Post
    It worked for me.
    The .Resize syntax is correct.
    Did you copy\paste the code as is or did you type in the new code?
    Did you make any changes to the code?
    What is the error description?

    i first copied as it is.
    then i tried to type one by one. When i pressed f8, it cant proceed, it highlights the first code row below:

    Worksheets("PO Summary").Cells(erow, 2).Resize(, 5).Value = _
    Sheets("PO Tracking Details").Cells(i, 2).Resize(, 5).Value

  8. #8
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: copy paste error to another sheet

    What is the error description?

  9. #9
    Registered User
    Join Date
    04-06-2016
    Location
    malaysia
    MS-Off Ver
    MS office 2013
    Posts
    12

    Re: copy paste error to another sheet

    Hi,

    i tried one more time. Delete everything and copy as it is. it works now.
    Thanks a lot!!!!!!

+ 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. When Activesheet.paste, Run-Time error '1004': Paste method of work sheet class failed.
    By devaraj2020 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-27-2015, 01:59 AM
  2. User Opens File - Copy and paste data from sheet - 400 error
    By cheeze83 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-10-2015, 09:37 AM
  3. Replies: 6
    Last Post: 03-26-2014, 11:40 PM
  4. [SOLVED] Copy And Paste on Another Sheet ( next time paste data from empty row )
    By HaroonSid in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-17-2014, 02:29 AM
  5. Replies: 1
    Last Post: 01-07-2013, 12:23 AM
  6. Cannot copy&paste chart to new sheet (runtime 1004 error)
    By bubastisbastet in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-13-2010, 07:13 AM
  7. Replies: 1
    Last Post: 01-04-2005, 06:06 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