Advertisement
Guest User

Untitled

a guest
Feb 8th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'стандартная экселевская функция COUNTIF не работает со строками больше 256 символов (
  2. 'This implementation does not require redundant call argument
  3. Public Function CountDuplicates_(rngRange As Range) As Integer
  4. Dim wsCur As Worksheet
  5.  
  6. Dim CallerRange As Range
  7.  
  8. Dim rngCol As Integer
  9.  
  10. Dim CheckCell As String
  11. Dim theCell As String   'Current test value
  12.  
  13. Dim CallerRow, StartRow, EndRow, iRow As Integer
  14.  
  15. Set CallerRange = Application.Caller
  16.  
  17. rngCol = rngRange.Cells(1, 1).Column
  18.  
  19. CallerRow = CallerRange.Row
  20. StartRow = rngRange.Cells(1, 1).Row
  21. EndRow = StartRow + rngRange.Rows.Count - 1
  22.  
  23. CountDuplicates_ = 0        ' API FIX
  24.  
  25. Set wsCur = ThisWorkbook.Application.Caller.Worksheet
  26.  
  27. CheckCell = wsCur.Cells(CallerRow, rngCol).Value
  28.  
  29. If CheckCell = "" Then
  30.     'Return operator simulation
  31.    GoTo EndFunction
  32. End If
  33.  
  34. 'FIXME: Remove hardcode. Use Model, Luke
  35. For iRow = StartRow To EndRow
  36.     If iRow = CallerRow Then
  37.         'Continue operator simulation
  38.        GoTo Continue_iRow
  39.     End If
  40.  
  41.     theCell = wsCur.Cells(iRow, rngCol).Value
  42.    
  43.     If theCell <> CheckCell Then
  44.         'Current Cell is not equals test value
  45.        'Continue operator simulation
  46.        GoTo Continue_iRow
  47.     End If
  48.  
  49.     CountDuplicates_ = CountDuplicates_ + 1
  50.  
  51. Continue_iRow:
  52. Next iRow
  53.  
  54. EndFunction:
  55. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement