VBA Paste Entire Row over existing row by matching row A

dturgel

Board Regular
Joined
Aug 6, 2015
Messages
58
Hi,

I have the following code for copying and pasting an entire row from one spreadsheet into another:

Sub ExportRow72()


'Declare Variables
Dim MyRange As Range, rng As Worksheet
Set rng = Workbooks("2012 to 2016 bound new test VBA").Sheets("2015 CLASH")
Set MyRange = Workbooks("Copy of Mkt Curve Tool Working Copy SW v3").Sheets("Summary In 2").Rows(72)
MyRange.Copy
rng.Range("a" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues


End Sub

But instead of pasting into the last row, I want to lookup/match the value in column A and paste over that row (the rows are the exact same values so each cell will match one for one) - any idea how to do that? Also, my row has cells that are both numbers and formulae, any idea which member of xlPasteType class I should use?

Thanks!

Daniel
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
No worries you just need to add a match in there.

RowId = APplication.WorksheetFunction.Match( Cell Ref , rng.columns(1),0)

then change the paste

rng.Cells(RowID,1).PasteSpecial xlPasteValues
 
Upvote 0
Hi,

I was getting an error on the RowID line but then I saw another thread which said to change application.worksheetfunction.match to application.match and that got me past that line but now the final line is yielding a type mismatch (Error 13) error - any advice?

Also, is there any way to do this cell by cell so that I can paste values when I need to paste values and paste formulas when I need to paste formulas?

Daniel
 
Upvote 0
This is what I ended up doing and it seems to work:

'Declare Variables
Dim MyRange As Range
Set rng = Workbooks("2012 to 2016 bound new test VBA").Sheets("2016 CLASH")
Set MyRange = Workbooks("Copy of Mkt Curve Tool Working Copy SW v3").Sheets("Summary In 2").Rows(103)
RowID = Application.Match(MyRange.Columns(1), rng.Columns(1), 0)
MyRange.Rows.Copy
rng.Rows(RowID).PasteSpecial xlPasteValues
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,580
Messages
6,125,652
Members
449,245
Latest member
PatrickL

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