View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
somethinglikeant somethinglikeant is offline
external usenet poster
 
Posts: 94
Default update Records reference to new file

This should do it

::::::::::::::::::::::::::::

Sub AddEntries()

Set qrange = Workbooks("File A").Sheets("Sheet1").Range("A:A")
Set prange = Workbooks("File B").Sheets("Sheet1").Range("A:b")
Sheets("Sheet1").Range("A2").Select

Do Until IsEmpty(ActiveCell)
On Error Resume Next
ActiveCell.Offset(0, 4).Value = _
Application.WorksheetFunction.VLookup(ActiveCell.V alue, prange, 2, 0)
ActiveCell.Offset(1, 0).Select
On Error GoTo 0
Loop


Windows("File B").Activate
Sheets("Sheet1").Range("A2").Select

Do Until IsEmpty(ActiveCell)
qname = ActiveCell.Value
qage = ActiveCell.Offset(0, 1).Value

If Application.WorksheetFunction.CountIf(qrange, qname) = 0 Then
Windows("File A").Activate
ActiveCell.Value = qname

ActiveCell.Offset(0, 4) = qage
ActiveCell.Offset(1, 0).Select

Windows("File B").Activate
End If
ActiveCell.Offset(1, 0).Select

Loop

End Sub


:::::::::::::::::::::::::::::::::::::::