Copy from one workbook to another workbook

orion1951

New Member
Joined
Jul 8, 2019
Messages
3
Hi,


I have the following code in a master spreadsheet that I am using to try and copy rows from one workbook to another workbook depending on the value in column R in the source workbook. Both workbooks are opening OK but nothing is getting copied across, any advice please?.


Thx,


John


Sub CopyToMasterArchive()

Dim WBs As Workbook
Dim WBd As Workbook
Dim WSs As Worksheet
Dim WSd As Worksheet

Dim WRSLocation As String
Dim WRSLivelist As String
Dim WRSArchive As String
Dim Sr As Long
Dim Dr As Long
Dim r As Long

WRSLocation = "\\5p6fs003\5p6p-rdf\Home First"
WRSLivelist = WRSLocation & "WRS Livelist.xlsx"
WRSArchive = WRSLocation & "WRS Master Archive.xlsx"

Set WBs = Workbooks.Open(WRSLivelist)
Set WSs = WBs.Worksheets("Summary")
Set WBd = Workbooks.Open(WRSArchive)
Set WSd = WBd.Worksheets("Data")

Sr = WSs.Cells(Rows.Count, "A").End(xlUp).Row
Dr = WSd.Cells(Rows.Count, "A").End(xlUp).Row
For r = Sr To 2 Step -1
If Range("R" & r).Value = "Y" Then
Rows(r).Copy Destination:=WSd.Range("A" & Dr + 1)
Dr = WSd.Cells(Rows.Count, "A").End(xlUp).Row
End If
Range("A1").Select
Next r

End Sub
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

Forum statistics

Threads
1,214,583
Messages
6,120,380
Members
448,955
Latest member
BatCoder

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