I'm new to vba programming and was trying to make a pc of code using bits of info from the net, but it isn't working. pls some one help me write it.
problem:
i have two files a.xls and b.xls . in a.xls (sheet 1) there is a column(column A) with names of people. And in b.xls(sheet 1) in column A there is a longer list of names and in column B their phone nos. i want to write a vba code to take each name in a.xls and find it in b.xls and take the phone no. from b.xls and write it into the first file.
this is the code iv written, you may correct it or write ur own:
Sub macro1()
ThisWorkbook.Activate
ActiveSheet.Name = file1
rows = ActiveSheet.UsedRange.Rows.Count
For Row = 1 To rows
Dim a As String
a = Cells(Row, 1).Value
Windows("b.xls").Activate
Sheets("sheet1").Activate
Dim b As Long
b = WorksheetFunction.Match(a, Range("a1:a28"))
Dim c As Long
c = Cells(b , 2).Value
Windows("a.xls").Activate
Sheets("file1").Activate
Cells(Row, 2).Value = c
Next Row
End Sub
Bookmarks