Advertisement
Guest User

Untitled

a guest
Oct 21st, 2014
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. Function BinarySearch(lookupArray As Variant, lookupValue As Variant) As Integer
  2.  
  3. Dim intLower As Integer
  4. Dim intMiddle As Integer
  5. Dim intUpper As Integer
  6.  
  7. intLower = LBound(lookupArray) 'type mismatch error here
  8. intUpper = UBound(lookupArray)
  9.  
  10. Do While intLower < intUpper
  11. intMiddle = (intLower + intUpper) 2
  12. If lookupValue > lookupArray(intMiddle) Then
  13. intLower = intMiddle + 1
  14. Else
  15. intUpper = intMiddle
  16. End If
  17. Loop
  18. If lookupArray(intLower) = lookupValue Then
  19. BinarySearch = intLower
  20. Else
  21. BinarySearch = -1 'search does not find a match
  22. End If
  23.  
  24. Sub Compare()
  25.  
  26. Dim h As Integer
  27.  
  28. For h = 1 To 1000 'iterate through rows of PLANNING BOARD
  29.  
  30. If Sheets("PLANNING BOARD").Cells(h, 6) <> "" Then 'I want to ignore blank cells
  31.  
  32. Dim i As Integer
  33. i = BinarySearch(Sheets("Copy").Range("A:A"), Sheets("PLANNING BOARD").Cells(h, 6))
  34.  
  35. If i <> -1 Then
  36. 'delete row and shift up
  37. Sheets("Copy").Rows(i).EntireRow.Delete Shift:=xlUp
  38. End If
  39.  
  40. End If
  41.  
  42. Next h
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement