• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Code for pasting in last row

Status
Not open for further replies.

Veeru106

Member
Hi,


I have code which will allow me to select a file with data from my documents and then paste in my excel sheet .


But can we modify it so that it paste in my main sheet below the already existing data in Col. B.
means it first find last row and then paste in from col. B
Code:
Sub Copy()
Dim vFile As Variant
Dim wbCopyTo As Workbook
Dim wsCopyTo As Worksheet
Dim wbCopyFrom As Workbook
Dim wsCopyFrom As Worksheet

Set wbCopyTo = ActiveWorkbook
Set wsCopyTo = ActiveSheet

    '-------------------------------------------------------------
    'Open file with data to be copied
  
    vFile = Application.GetOpenFilename("Excel Files (*.xl*)," & _
    "*.xl*", 1, "Select Excel File", "Open", False)
  
    'If Cancel then Exit
    If TypeName(vFile) = "Boolean" Then
        Exit Sub
    Else
    Set wbCopyFrom = Workbooks.Open(vFile)
    Set wsCopyFrom = wbCopyFrom.Worksheets(1)
    End If
  
    '--------------------------------------------------------------
    'Copy Range
    wsCopyFrom.Range("A2:N700").Copy
    wsCopyTo.Range("A1").PasteSpecial Paste:=xlPasteValues, _
            Operation:=xlNone, SkipBlanks:=False, Transpose:=False
  
    'Close file that was opened
    wbCopyFrom.Close SaveChanges:=False

End Sub
onwards

Right now it is pasting it as it is..


<EDITED>
Do not open duplicate threads, keep on writing at the original one:
http://chandoo.org/forum/threads/code-for-pasting-data-in-last-row.34858/
 
Last edited by a moderator:
Status
Not open for further replies.
Back
Top