I have two workboks, one called slave and one called master.
Slave.xlsm
ID Case Size Names
1 1o Michael
2 4 Katie
3 3 Elliot
Master.xlsm
ID Case Size Names
1 1o
2 4
3 3
From Slave workbook, I am trying to copy the values from Name column where the ID and Case Size matches in Master.
I'm new to VBA and so have tried to compile my own code below with the help of some examples online. Here's what i've got so far:
Sub GetTheName()
Dim s As String, FileName As String
s = "C:\Users\******\Documents\*.xlsm"
FileName = Dir(s)
Do Until FileName = ""
If FileName Like "Slave*" Then MsgBox FileName
Dim w1 As Worksheet, w2 As Worksheet
Dim c As Range, FR As Long
Application.ScreenUpdating = False
Set w1 = Workbooks.Open(FileName).Sheets(1)
Set w2 = ThisWorkbook.Sheets(1)
For Each c In w1.Range("C10", w1.Range("C" & Rows.Count).End(xlUp))
FR = 0
On Error Resume Next
FR = Application.Match(c, w2.Columns("A"), 0)
On Error GoTo 0
If FR <> 0 Then w2.Range("R" & FR).Value = c.Offset(, 0)
Next c
Application.ScreenUpdating = True
FileName = Dir()
ActiveSheet.Range("A8").Value = Now()
Loop
End Sub
If i remove On Error Resume Next i get a type mismatch error on the below line:
FR = Application.Match(c, w2.Columns("R"), 0)
The code opens the workbok but does not copy anything across. I'm not sure why nothing is being copied. Please can someone show me where i am going wrong? Thanks