View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.misc
Gabor
 
Posts: n/a
Default merging two files


This one I made up for similar purposes many years ago, means you have
to really tweak it to your needs. Assumes you have the two lists in the
same workbook and there are no empty cells util the end of the list.
So wherever there is an UPDATE indicated you have to change the
code as per your workbook.

Sub Vergleich()

Dim ToList, FromList
Dim Friss, RefData
Dim RefTav
Dim StartCell

ToList = "St"
' Name of ToList <<<<<<<<UPDATE rqd. !!!
FromList = "List"
' Name of FromList <<<<<<<<UPDATE rqd.!!!
RefTav = 0
' Offset of the reference data element <<UPDATE !!!
StartCell = "A1"
' This is the starting cell on the ToList <<UPDATE !!!

Sheets(ToList).Select
Range(StartCell).Select
Sheets(FromList).Select
Range("A1").Select
' Starting Cell at FromList <<<<<<<<UPDATE !!!

For cik01 = 1 To 20000

ActiveCell.Offset(1, 0).Select
If ActiveCell.Offset(0, RefTav) = Empty Then GoTo 1000
'If ref. data is empty, quit
Friss = ActiveCell
RefData = ActiveCell.Offset(0, RefTav)
Sheets(ToList).Select
Range(StartCell).Select '<<<<<<<<<< UPDATE RQD.

For cik02 = 1 To 2000

ActiveCell.Offset(1, 0).Select

If ActiveCell.Offset(0, RefTav) = RefData Then
ActiveCell.Formula = Friss
ActiveCell.Offset(0, 12).FormulaR1C1 = "matched"
'<<<<UPDATE
Range(StartCell).Select
Sheets(FromList).Select
ActiveCell.Offset(0, 12).FormulaR1C1 = "matched"
'<<<<UPDATE
GoTo 100
ElseIf ActiveCell.Offset(0, RefTav) = Empty Then
Range(StartCell).Select
Sheets(FromList).Select
ActiveCell.Offset(0, 12).FormulaR1C1 = _
"not found"
'<<<<UPDATE
GoTo 100
Else
End If

Next cik02

100 Next cik01

1000 Beep

End Sub


Cheers, Gabor


--
Gabor
------------------------------------------------------------------------
Gabor's Profile: http://www.excelforum.com/member.php...fo&userid=6179
View this thread: http://www.excelforum.com/showthread...hreadid=531253