+ Reply to Thread
Results 1 to 2 of 2

VB for copying a selected range

Hybrid View

John McCann VB for copying a selected... 12-01-2011, 11:04 AM
tigeravatar Re: VB for copying a selected... 12-01-2011, 01:03 PM
  1. #1
    Registered User
    Join Date
    12-01-2011
    Location
    Liverpool
    MS-Off Ver
    Excel 2003
    Posts
    1

    Question VB for copying a selected range

    Hi, I am putting in some simple code to copy a selected range from a sheet and paste special into another sheet.

    But - I want the vb to be able to recognise what area has been highlighted by the user for copying and on click only paste that data into the new location.

    in other words selectedrange.copy etc

    but i cannot get this bit of code right

    many thanks
    John

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: VB for copying a selected range

    John McCann,

    Welcome to the forum!
    Give the following macro a try. You can change rngDest to be the desired location for the paste.
    Sub tgr()
        
        Dim rngDest As Range: Set rngDest = Sheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Offset(1)
        
        Dim rngCopy As Range
        On Error Resume Next
        Set rngCopy = Application.InputBox("Select the range to copy", "Range selection", , , , , , 8)
        If rngCopy Is Nothing Then Exit Sub
        
        rngCopy.Copy
        rngDest.PasteSpecial xlPasteValues
        
        Application.CutCopyMode = False
        
    End Sub
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

+ 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