I have two excel workbooks: 1- workbook has 19 columns and 8 rows and another workbook has 8 row names and 19 column names same like workbook1 but it doesnt contain any data. I need to copy range of data from workbook1 by exactly matching the rownames.
For example:
Workbook1:
icn id location
1 125 M
2 123 F
3 132 G
4 145 H
5 145 I
Workbook2:
icn id Location
1
3
5
4
2
I tried coding but I was not able to get the range of data :
Sub UpdateW2()
Dim w1 As Worksheet, w2 As Worksheet
Dim c As Range, FR As Long
Application.ScreenUpdating = False
Set w1 = Workbooks("workbookA.xlsm").Worksheets("Sheet1")
Set w2 = Workbooks("workbookB.xlsm").Worksheets("Sheet1")
For Each c In w1.Range("A2", w1.Range("A" & 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("C" & FR).Value = c.Offset(, 0)
Next c
Application.ScreenUpdating = True
End Sub