Advertisement
Guest User

Personal Project

a guest
Feb 12th, 2014
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Sub CompareLists()
  2.    
  3.     'variables
  4.    Dim i As Integer
  5.     Dim line As String
  6.     Dim howMany As Range
  7.     Dim filePath As String
  8.     Dim match As Boolean
  9.     match = False
  10.    
  11.     Dim list As New Collection
  12.     Set list = New Collection
  13.    
  14.     Dim rng As Range
  15.     Dim ms As Worksheet
  16.     Set ms = Sheets("Matrix")
  17.     Set rng = ms.Range("E9:E" & ms.Cells(ms.Rows.Count, 1).End(xlUp).Row)
  18.    
  19.     'code
  20.  
  21.     Application.ScreenUpdating = False 'disable the screen updating
  22.    
  23.     'opening and preparing the the input file
  24.    filePath = "R:\CLASSES\CIS2085Students\Michal Mazur\UPGRADE\Updated lists 20130912123600\ZEN\ZEN last 4.txt"
  25.     Dim fso As FileSystemObject
  26.     Set fso = New FileSystemObject
  27.     Set txtStream = fso.OpenTextFile(filePath, ForReading, False)
  28.    
  29.    
  30.     'addidng elements to the collection (reading from the input file)
  31.    Do While Not txtStream.AtEndOfStream
  32.         line = txtStream.ReadLine
  33.         list.Add line
  34.        
  35.     Loop
  36.    
  37.     'close the input file (all the elements are in the collection list)
  38.    txtStream.Close
  39.    
  40.    
  41.     For i = 1 To list.Count     'for each element in the collection check for match
  42.        Range("E9").Select
  43.         For Each howMany In rng
  44.             'found match between the two lists
  45.            If ActiveCell.Value = list(i) Then
  46.                 found = True
  47.                 ActiveCell.Offset(0, 2) = list(i)
  48.                
  49.             End If
  50.             'else
  51.            ActiveCell.Offset(1, 0).Select
  52.        
  53.         Next
  54.    
  55.     Next i
  56.    
  57.     Application.ScreenUpdating = True
  58.     Range("A9").Select
  59. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement