Need VBA to copy active row and paste it in last row of another sheet

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>
 
not quite, try
Code:
Sub copypasterow()
Dim wsTarget As Worksheet
Dim rng As Range

Set rng = activecell

Set wsTarget = Workbooks("asdf.xlsx").Sheets("Sheet1")
rng.EntireRow.Copy wsTarget.Rows(wsTarget.Cells.find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Offset(1).Row)
End Sub

This is it exactly what i wanted ! Thank you so much. I was trying to find this macro for 2 weeks now on different forums. I wish you well, stay blessed.
 
Upvote 0

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,189
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top