Параметры в VBA


/ Published in: Visual Basic
Save to your folder(s)

Создание процедуры с переменным числом параметров и обработка этих параметров


Copy this code and paste it in your HTML
  1. Public Function IsMediana(M As Variant, Cand As Variant) As Integer
  2.  
  3. Dim Pos As Integer, Neg As Integer
  4. Pos = 0: Neg = 0
  5. If TypeName(M) = "Range" Then
  6. For i = 1 To M.Rows.Count
  7. For j = 1 To M.Columns.Count
  8. If M.Cells(i, j) > Cand Then
  9. Pos = Pos + 1
  10. ElseIf M.Cells(i, j) < Cand Then
  11. Neg = Neg + 1
  12. End If
  13. Next j
  14. Next i
  15. IsMediana = Pos - Neg
  16.  
  17. ElseIf TypeName(M) = "Variant()" Then
  18. 'TypeName is "Variant()"
  19. Dim Val As Variant
  20. For Each Val In M
  21. If Val > Cand Then
  22. Pos = Pos + 1
  23. ElseIf Val < Cand Then
  24. Neg = Neg + 1
  25. End If
  26. Next Val
  27. IsMediana = Pos - Neg
  28. Else
  29. MsgBox ("")
  30. End If
  31.  
  32. End Function

URL: http://www.intuit.ru/department/office/vbaexcel/2/vbaexcel_2.html

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.