+ Reply to Thread
Results 1 to 4 of 4

Paste Value After Data

Hybrid View

  1. #1
    Registered User
    Join Date
    02-20-2009
    Location
    las vegas, nevada
    MS-Off Ver
    Excel 2007
    Posts
    1

    Paste Value After Data

    I am attempting to copy data from sheet A (macro_sort) and paste value in sheet B (book) at the end of the data in sheet B. I am constantly adding data to sheet B so I need it to paste the new data after the existing data. I have included a copy of the code I am using. Currently it is pasting the data but not by value and not after the existing data; it is wiping out much of the existing data.

    Sub book()
    Dim a, b As Long
    a = Sheets("macro_sort").Range("A" & Rows.Count).End(xlUp).Row
    b = Sheets("book").Range("A" & Rows.Count).End(xlUp).Row
    Sheets("macro_sort").Range("C4:H" & 5000).Copy Destination:=Sheets("book").Range("B" & b)
    End Sub
    My macro skills are very very basic so I would appreciate any help in the most simplest of terms.

    Thank you
    Luke
    Last edited by luke6843; 02-20-2009 at 01:49 AM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Paste Value After Data

    Welcome to the forum.

    Please take a few minutes to read the Forum Rules, and then edit your post to wrap your code with Code Tags.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Paste Value After Data

    Try this
    Option Explicit
    
    Sub book()
        Dim rCopy  As Range
        Dim lRw    As Long
        lRw = Sheets("book").Cells(Rows.Count, 1).End(xlUp).Row + 1
        With Sheets("macro_sort")
            Set rCopy = .Range(.Cells(4, 3), .Cells(.Rows.Count, 8).End(xlUp))
            rCopy.Copy
            Sheets("book").Cells(lRw, 1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                                                                                               :=False, Transpose:=False
        End With
    End Sub
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Paste Value After Data

    Luke, on an aside and given you're beginning your VBA journey note that this:

    Dim a, b As Long
    is equivalent to coding

    Dim a As Variant, b As Long
    if you want "a" to be a Long also you must declare explicitly in VBA

    Dim a As Long, b As Long

+ 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