Advertisement
drAnger

Функции для подсчета студентов

Dec 11th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function CountCellsByColor(rData As Range, cellRefColor As Range) As Long
  2.     ' Функция считает количество ячеек выбранного цвета
  3.  
  4.     Dim indRefColor As Long
  5.     Dim cellCurrent As Range
  6.     Dim cntRes As Long
  7.  
  8.     Application.Volatile
  9.     cntRes = 0
  10.     indRefColor = cellRefColor.cells(1, 1).Interior.Color
  11.     For Each cellCurrent In rData
  12.         If indRefColor = cellCurrent.Interior.Color Then
  13.             cntRes = cntRes + 1
  14.         End If
  15.     Next cellCurrent
  16.  
  17.     CountCellsByColor = cntRes
  18. End Function
  19.  
  20. Function CountCellsByFontBold(rData As Range) As Integer
  21.  
  22.     Dim count As Integer
  23.     Dim cell As Range
  24.     For Each cell In rData
  25.         If cell.Font.Bold = True Then
  26.             CountCellsByFontBold = CountCellsByFontBold + 1
  27.         End If
  28.     Next cell
  29. End Function
  30.  
  31. Function CountBungedPeople(Диапазон As Range, СсылкаНаЦвет As Range) As Integer
  32.     ' Функция предназначена для подсчета количества студентов, обучающихся на бюджете
  33.    ' Принипает в себя два аргумента: диапазон значений (диапазаон студентов) и ячейку с цветом, обозначающий, что студент выбыл
  34.    
  35.     Dim count As Integer
  36.     Dim cellCurrent As Range
  37.     Dim refColor As Long
  38.    
  39.     Application.Volatile
  40.     count = 0
  41.     refColor = СсылкаНаЦвет.cells(1, 1).Interior.Color
  42.    
  43.     For Each cellCurrent In Диапазон
  44.         If cellCurrent.Font.Bold = False Then
  45.             count = count + 1
  46.             If refColor = cellCurrent.Interior.Color Then
  47.                 count = count - 1
  48.             End If
  49.         End If
  50.     Next cellCurrent
  51.    
  52.     CountBungedPeople = count
  53. End Function
  54.  
  55. Function CountCommercialPeople(Диапазон As Range, СсылкаНаЦвет As Range) As Integer
  56.     ' Функция предназначена для подсчета количества студентов, обучающихся на коммерции
  57.    ' Принипает в себя два аргумента: диапазон значений (диапазаон студентов) и ячейку с цветом, обозначающий, что студент выбыл
  58.    
  59.     Dim count As Integer
  60.     Dim cellCurrent As Range
  61.     Dim refColor As Long
  62.    
  63.     Application.Volatile
  64.     count = 0
  65.     refColor = СсылкаНаЦвет.cells(1, 1).Interior.Color
  66.    
  67.     For Each cellCurrent In Диапазон
  68.         If cellCurrent.Font.Bold = True Then
  69.             count = count + 1
  70.             If refColor = cellCurrent.Interior.Color Then
  71.                 count = count - 1
  72.             End If
  73.         End If
  74.     Next cellCurrent
  75.    
  76.     CountCommercialPeople = count
  77. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement