+ Reply to Thread
Results 1 to 5 of 5

Paste after last row of data from one sheet to another

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-10-2012
    Location
    Slovakia
    MS-Off Ver
    Excel 365
    Posts
    174

    Paste after last row of data from one sheet to another

    Hi friends,

    I am trying to write down macro code which should make following.

    1. In sheet called "Pivot" data from columns Q1:S copy until the last row
    2. Copied data paste into Sheet "DFI" and paste it into column A, but at the end (there can exists some prior data which couldn't be replaced).

    I got something ,but it doesn't work due Run-time error, Object doesn't support....

    Could you pls help me fix it?

    Sub CopyData()
    Dim lastRow As Integer
    
     'Select the sheet with the data
    Sheets("Pivot").Select
    
    'Find the last row in the dataset
    lastRow = Range("Q1").End(xlDown).Row
    
    
    'Select the rows of data
    Range("Q1:S" & lastRow).Select
    Selection.SpecialCells(xlCellTypeVisible).Select
    
    'Copy the data
    Selection.Copy
    
    'Select the sheet data will be copied to
    Sheets("DFI").Select
    Dim lastRow2 As String
    lastRow2 = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row + 1
    Range("A" & lastRow2).ActiveSheet.Paste
    
    End Sub

  2. #2
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Paste after last row of data from one sheet to another

    You have lastrow2 declared as a string, it should be a number.
    Click the * Add Reputation button in the lower left hand corner of this post to say thanks.

    Don't forget to mark this thread SOLVED by going to the "Thread Tools" drop down list above your first post and choosing solved.

  3. #3
    Forum Contributor
    Join Date
    09-10-2012
    Location
    Slovakia
    MS-Off Ver
    Excel 365
    Posts
    174

    Re: Paste after last row of data from one sheet to another

    If I changed it as follows, it doesn't work and Compile error occured
    Dim lastRow2 As Number

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Paste after last row of data from one sheet to another

    Option Explicit
    
    Sub CopyData()
    Dim lastRow As Long
    
    lastRow = Sheets("Pivot").Range("Q" & Rows.Count).End(xlUp).Row
    
    Sheets("Pivot").Range("Q1:S" & lastRow).SpecialCells(xlCellTypeVisible).Copy
    
    Sheets("DFI").Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlValues
    
    End Sub

  5. #5
    Forum Contributor
    Join Date
    09-10-2012
    Location
    Slovakia
    MS-Off Ver
    Excel 365
    Posts
    174

    Re: Paste after last row of data from one sheet to another

    Thank you AB33, it works.

+ 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. Replies: 6
    Last Post: 03-26-2014, 11:40 PM
  2. [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
  3. Replies: 0
    Last Post: 05-21-2013, 03:09 PM
  4. How to copy data with formula and paste another sheet as paste spl -value only
    By sumesh56 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-14-2013, 09:03 PM
  5. [SOLVED] Copy and paste data from sheet 2 to sheet 1 based on specific criteria on sheet 1
    By VBADUD in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-05-2012, 04:18 AM
  6. Copy Sheet / Create & Name New Sheet / Insert Before a Sheet / Paste Data
    By thinkspac in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-12-2012, 02:27 PM
  7. [SOLVED] Paste data from source sheet to data sheet using 1st available row within a named range.
    By Krex14 in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 08-28-2012, 08:14 AM
  8. Replies: 2
    Last Post: 02-22-2011, 02:07 AM

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