какой добавить в visual basic код позволяющий пропускать пустые ячейки?
#38076528
Ссылка:
Ссылка на сообщение:
Ссылка с названием темы:
|
|
|
Shocker.Pro,
Мне нужно добавить в модуль.
Так что бы все пустые ячейки пропускались.
Вот не большой код:
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82. 83. 84. 85. 86. 87. 88. 89. 90. 91. 92. 93. 94. 95. 96. 97. 98. 99. 100. 101. 102. 103. 104. 105. 106. 107. 108. 109. 110. 111. 112. 113. 114. 115. 116. 117. 118. 119. 120. 121. 122. 123. 124. 125. 126. 127. 128. 129. 130. 131. 132. 133. 134. 135. 136. 137. 138. 139. 140. 141. 142. 143. 144. 145. 146. 147. 148. 149. 150. 151. 152. 153. 154. 155. 156. 157. 158. 159. 160. 161. 162. 163. 164. 165. 166. 167. 168. 169. 170. 171. 172. 173. 174. 175. 176. 177. 178. 179. 180. 181. 182. 183. 184. 185. 186. 187. 188. 189. 190. 191. 192. 193. 194. 195. 196. 197. 198. 199. 200. 201. 202. 203. 204. 205. 206. 207. 208. 209. 210. 211. 212. 213. 214. 215. 216. 217. 218. 219. 220.
Public Sub Stipend()
Dim stip1 As Boolean
Dim stip2 As Boolean
Dim stip3 As Boolean
Dim stip4 As Boolean
Dim stip5 As Boolean
Dim sov As Boolean
Dim YesNo As String
Dim a As Integer
Dim b As Integer
Dim n As Integer
Dim c As Integer
Dim d As Integer
Dim Per As Integer
Dim Vtor As Integer
Dim Pyat As Integer
Dim Koef As Single
n = 2
a = 1
Do While (Sheets(UserForm1.ComboBox1.Text).Cells(a, 1) <> "") And (Sheets(UserForm1.ComboBox1.Text).Cells(a + 1, 1) <> "")
If Sheets(UserForm1.ComboBox1.Text).Cells(a, 1) = UserForm1.ComboBox2.Text Then
a = a + 2
Per = a - 1
Exit Do
End If
a = a + 1
Loop
Do While Sheets(UserForm1.ComboBox1.Text).Cells(a, 2) <> ""
Pyat = 0
Max = 0
Koef = 0
c = 0
stip1 = True
stip2 = True
stip3 = True
stip4 = True
stip5 = True
For b = 3 To 19
If Sheets(UserForm1.ComboBox1.Text).Cells(Per, b) <> "" Then
c = c + 1
If Sheets(UserForm1.ComboBox1.Text).Cells(a, b) < 4 Or Sheets(UserForm1.ComboBox1.Text).Cells(a, b) = "" Or Sheets(UserForm1.ComboBox1.Text).Cells(a, b) = "н/а" Or Sheets(UserForm1.ComboBox1.Text).Cells(a, b) = "н\а" Then
stip1 = False
End If
If Sheets(UserForm1.ComboBox1.Text).Cells(a, 23) <> "" Then
stip2 = False
End If
If Sheets(UserForm1.ComboBox1.Text).Cells(a, 24) = "к" Then
stip3 = False
End If
If Sheets(UserForm1.ComboBox1.Text).Cells(a, b) = 5 Or Sheets(UserForm1.ComboBox1.Text).Cells(a, b) = "зач" Then
Pyat = Pyat + 1
End If
End If
Next b
'---------------------------------------------------------------
If stip1 = True Then
d = 1
Do While (Sheets(UserForm1.ComboBox1.Text).Cells(d, 1) <> "") And (Sheets(UserForm1.ComboBox1.Text).Cells(d + 1, 1) <> "")
If Sheets(UserForm1.ComboBox1.Text).Cells(d, 1) = UserForm1.ComboBox2.List(UserForm1.ComboBox2.ListIndex - 1) Then
d = d + 2
Vtor = d - 1
sov = False
Do While Sheets(UserForm1.ComboBox1.Text).Cells(d, 2) <> ""
If Sheets(UserForm1.ComboBox1.Text).Cells(d, 2) = Sheets(UserForm1.ComboBox1.Text).Cells(a, 2) Then
sov = True
For b = 3 To 19
If Sheets(UserForm1.ComboBox1.Text).Cells(Vtor, b) <> "" Then
If Sheets(UserForm1.ComboBox1.Text).Cells(d, b) = 3 Or Sheets(UserForm1.ComboBox1.Text).Cells(d, b) = 2 Or Sheets(UserForm1.ComboBox1.Text).Cells(d, b) = "" Or Sheets(UserForm1.ComboBox1.Text).Cells(d, b) = "н/а" Or Sheets(UserForm1.ComboBox1.Text).Cells(d, b) = "н\а" Then
stip4 = False
End If
End If
Next b
End If
d = d + 1
Loop
End If
d = d + 1
Loop
If stip4 = False Then
stip1 = False
End If
If sov = False Then
YesNo = MsgBox("Студент " & Sheets(UserForm1.ComboBox1.Text).Cells(a, 2) & " не найден в предыдущем месяце." & vbCrLf & vbCrLf & "Остановить программу для проверки?", vbYesNo, "Ошибка")
If YesNo = vbYes Then
Application.DisplayAlerts = False
ActiveWorkbook.Worksheets(UserForm1.ComboBox1.Text & "_Стипендия").Delete
Application.DisplayAlerts = True
Exit Sub
Else
End If
End If
If UserForm1.ComboBox2.Text = "Октябрь" Or UserForm1.ComboBox2.ListIndex > 1 Then
d = 1
Do While (Sheets(UserForm1.ComboBox1.Text).Cells(d, 1) <> "") And (Sheets(UserForm1.ComboBox1.Text).Cells(d + 1, 1) <> "")
If Sheets(UserForm1.ComboBox1.Text).Cells(d, 1) = UserForm1.ComboBox2.List(UserForm1.ComboBox2.ListIndex - 2) Then
d = d + 2
Do While Sheets(UserForm1.ComboBox1.Text).Cells(d, 2) <> ""
If Sheets(UserForm1.ComboBox1.Text).Cells(d, 2) = Sheets(UserForm1.ComboBox1.Text).Cells(a, 2) Then
For b = 3 To 19
If Sheets(UserForm1.ComboBox1.Text).Cells(d, b) <= 3 Then
If UserForm1.ComboBox2.Text = "Октябрь" Then
stip5 = False
Else
If UserForm1.ComboBox2.ListIndex > 1 Then
stip1 = False
End If
End If
End If
Next b
End If
d = d + 1
Loop
End If
d = d + 1
Loop
If UserForm1.ComboBox2.Text = "Октябрь" Then
If stip4 = True Or stip5 = True Then
stip1 = True
End If
End If
End If
End If
'----------------------------------------------------------------
If c > 0 Then
Koef = Pyat / c * 100
End If
If (stip2 = True) And (stip3 = True) Then
If ((stip1 = True) And (stip2 = True) And (stip3 = True) And (c > 0)) Or Sheets(UserForm1.ComboBox1.Text).Cells(a, 25) <> "" Then
If (stip1 = True) And (stip2 = True) And (stip3 = True) And (c > 0) Then
Sheets(UserForm1.ComboBox1.Text & "_Стипендия").Cells(n, 1) = Sheets(UserForm1.ComboBox1.Text).Cells(a, 2)
If (Koef >= 75) And (Koef <= 100) Then
Sheets(UserForm1.ComboBox1.Text & "_Стипендия").Cells(n, 2) = 3
Sheets(UserForm1.ComboBox1.Text & "_Стипендия").Cells(n, 5) = Sheets(UserForm1.ComboBox1.Text & "_Стипендия").Cells(n, 5) + "за отличную успеваемость "
End If
If (Koef >= 50) And (Koef < 75) Then
Sheets(UserForm1.ComboBox1.Text & "_Стипендия").Cells(n, 2) = 2
Sheets(UserForm1.ComboBox1.Text & "_Стипендия").Cells(n, 5) = Sheets(UserForm1.ComboBox1.Text & "_Стипендия").Cells(n, 5) + "за хорошую успеваемость "
End If
If (Koef >= 25) And (Koef < 50) Then
Sheets(UserForm1.ComboBox1.Text & "_Стипендия").Cells(n, 2) = 1.5
Sheets(UserForm1.ComboBox1.Text & "_Стипендия").Cells(n, 5) = Sheets(UserForm1.ComboBox1.Text & "_Стипендия").Cells(n, 5) + "за хорошую успеваемость "
End If
If Koef < 25 Then
Sheets(UserForm1.ComboBox1.Text & "_Стипендия").Cells(n, 2) = 1.25
Sheets(UserForm1.ComboBox1.Text & "_Стипендия").Cells(n, 5) = Sheets(UserForm1.ComboBox1.Text & "_Стипендия").Cells(n, 5) + "за хорошую успеваемость "
End If
End If
If Sheets(UserForm1.ComboBox1.Text).Cells(a, 25) = "Ст" Or Sheets(UserForm1.ComboBox1.Text).Cells(a, 25) = "Староста" Then
Sheets(UserForm1.ComboBox1.Text & "_Стипендия").Cells(n, 1) = Sheets(UserForm1.ComboBox1.Text).Cells(a, 2)
Sheets(UserForm1.ComboBox1.Text & "_Стипендия").Cells(n, 3) = 1
If Sheets(UserForm1.ComboBox1.Text & "_Стипендия").Cells(n, 2) <> "" Then
Sheets(UserForm1.ComboBox1.Text & "_Стипендия").Cells(n, 5) = Sheets(UserForm1.ComboBox1.Text & "_Стипендия").Cells(n, 5) + "(" + CStr(Sheets(UserForm1.ComboBox1.Text & "_Стипендия").Cells(n, 2)) + "), " + "за исполнение обязанностей старосты (1) "
Else
Sheets(UserForm1.ComboBox1.Text & "_Стипендия").Cells(n, 5) = Sheets(UserForm1.ComboBox1.Text & "_Стипендия").Cells(n, 5) + "за исполнение обязанностей старосты "
End If
Else
If Sheets(UserForm1.ComboBox1.Text).Cells(a, 25) = "Зам" Or Sheets(UserForm1.ComboBox1.Text).Cells(a, 25) = "Заместитель" Then
Sheets(UserForm1.ComboBox1.Text & "_Стипендия").Cells(n, 1) = Sheets(UserForm1.ComboBox1.Text).Cells(a, 2)
Sheets(UserForm1.ComboBox1.Text & "_Стипендия").Cells(n, 3) = 0.5
If Sheets(UserForm1.ComboBox1.Text & "_Стипендия").Cells(n, 2) <> "" Then
Sheets(UserForm1.ComboBox1.Text & "_Стипендия").Cells(n, 5) = Sheets(UserForm1.ComboBox1.Text & "_Стипендия").Cells(n, 5) + "(" + CStr(Sheets(UserForm1.ComboBox1.Text & "_Стипендия").Cells(n, 2)) + "), " + "за исполнение обязанностей зам. старосты (0.5)"
Else
Sheets(UserForm1.ComboBox1.Text & "_Стипендия").Cells(n, 5) = Sheets(UserForm1.ComboBox1.Text & "_Стипендия").Cells(n, 5) + "за исполнение обязанностей зам. старосты "
End If
End If
End If
If Sheets(UserForm1.ComboBox1.Text & "_Стипендия").Cells(n, 2) = "" Then
Sheets(UserForm1.ComboBox1.Text & "_Стипендия").Cells(n, 2) = 0
End If
If Sheets(UserForm1.ComboBox1.Text & "_Стипендия").Cells(n, 3) = "" Then
Sheets(UserForm1.ComboBox1.Text & "_Стипендия").Cells(n, 3) = 0
End If
If Sheets(UserForm1.ComboBox1.Text & "_Стипендия").Cells(n, 4) = "" Then
Sheets(UserForm1.ComboBox1.Text & "_Стипендия").Cells(n, 4) = 0
End If
n = n + 1
End If
End If
a = a + 1
Loop
YesNo = MsgBox("Назначит доп. стипендию?", vbYesNo, "Доп. стипендия")
If YesNo = vbYes Then
UserForm2.Show
End If
End Sub
Sub Кнопка6_Щелчок()
UserForm1.Show
End Sub
Модератор: Учимся использовать тэги оформления кода и убирать длинные простыни под спойлер - FAQ
|
|