forginganewone
Board Regular
- Joined
- Mar 14, 2018
- Messages
- 64
Need macro to copy active row and paste it in xfiles-xsheets-lastrow. With same format and everything.
I've tried this :
<code>Option Explicit
Sub copypasterow()
Dim wbTarget As Workbook
Selection.EntireRow.Copy
Set wbTarget = Workbooks.Open("C:\YOURPATH\FILE.xlsx")
wbTarget.Sheets("Sheet1").Range("B1").End(xlDown).Offset(1, -1).PasteSpecial
End Sub
And this:
<code>Option Explicit
Sub copypasterow()
Dim wbTarget As Workbook
Dim Filetarget As String
Dim WorksheetEndRow As Integer
Filetarget = "C:\Users\francesco.dinh\Downloads\asdf.xlsx"
Selection.EntireRow.Copy
Set wbTarget = Workbooks.Open(Filetarget)
WorksheetEndRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Range("A" & WorksheetEndRow + 1).PasteSpecial
Application.CutCopyMode = False
End Sub
It gives me following error :</code></code>[h=2]runtime error 1004 pastespecial method of range class failed[/h]<code><code></code></code>
I've tried this :
<code>Option Explicit
Sub copypasterow()
Dim wbTarget As Workbook
Selection.EntireRow.Copy
Set wbTarget = Workbooks.Open("C:\YOURPATH\FILE.xlsx")
wbTarget.Sheets("Sheet1").Range("B1").End(xlDown).Offset(1, -1).PasteSpecial
End Sub
And this:
<code>Option Explicit
Sub copypasterow()
Dim wbTarget As Workbook
Dim Filetarget As String
Dim WorksheetEndRow As Integer
Filetarget = "C:\Users\francesco.dinh\Downloads\asdf.xlsx"
Selection.EntireRow.Copy
Set wbTarget = Workbooks.Open(Filetarget)
WorksheetEndRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Range("A" & WorksheetEndRow + 1).PasteSpecial
Application.CutCopyMode = False
End Sub
It gives me following error :</code></code>[h=2]runtime error 1004 pastespecial method of range class failed[/h]<code><code></code></code>