Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub CompareLists()
- 'variables
- Dim i As Integer
- Dim line As String
- Dim howMany As Range
- Dim filePath As String
- Dim match As Boolean
- match = False
- Dim list As New Collection
- Set list = New Collection
- Dim rng As Range
- Dim ms As Worksheet
- Set ms = Sheets("Matrix")
- Set rng = ms.Range("E9:E" & ms.Cells(ms.Rows.Count, 1).End(xlUp).Row)
- 'code
- Application.ScreenUpdating = False 'disable the screen updating
- 'opening and preparing the the input file
- filePath = "R:\CLASSES\CIS2085Students\Michal Mazur\UPGRADE\Updated lists 20130912123600\ZEN\ZEN last 4.txt"
- Dim fso As FileSystemObject
- Set fso = New FileSystemObject
- Set txtStream = fso.OpenTextFile(filePath, ForReading, False)
- 'addidng elements to the collection (reading from the input file)
- Do While Not txtStream.AtEndOfStream
- line = txtStream.ReadLine
- list.Add line
- Loop
- 'close the input file (all the elements are in the collection list)
- txtStream.Close
- For i = 1 To list.Count 'for each element in the collection check for match
- Range("E9").Select
- For Each howMany In rng
- 'found match between the two lists
- If ActiveCell.Value = list(i) Then
- found = True
- ActiveCell.Offset(0, 2) = list(i)
- End If
- 'else
- ActiveCell.Offset(1, 0).Select
- Next
- Next i
- Application.ScreenUpdating = True
- Range("A9").Select
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement