Advertisement
Guest User

Untitled

a guest
Feb 5th, 2020
376
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.10 KB | None | 0 0
  1. Const DeviceColumn As Integer = 2
  2. Const DayColumn As Integer = 6
  3. Const DateCheckColumn As Integer = 4
  4. Const DateNextCheckColumn As Integer = 5
  5. Const StartRow As Integer = 7
  6.  
  7. Const WarningPeriod As Integer = 10
  8.  
  9. Private Sub Workbook_Open5()
  10.  
  11. Dim NextCheckDate As Date
  12. Dim LastRow As Integer
  13. Dim ExpiredChecksPeriodCount As Integer
  14. Dim NearestCheckPeriodCount As Integer
  15.  
  16.     With ThisWorkbook.Worksheets("Лист1")
  17.         LastRow = .Cells(.Rows.Count, DeviceColumn).End(xlUp).Row
  18.         .Columns(DayColumn).Interior.Pattern = xlNone
  19.         .Range(.Cells(StartRow, DayColumn), .Cells(LastRow, DayColumn)).ClearContents
  20.         For CurentRow = StartRow To LastRow
  21.             If Not IsEmpty(.Cells(CurentRow, DeviceColumn)) And _
  22.                Not IsEmpty(.Cells(CurentRow, DateCheckColumn)) And _
  23.                Not IsEmpty(.Cells(CurentRow, DateNextCheckColumn)) Then
  24.                
  25.                 NextCheckDate = CDate(.Cells(CurentRow, DateNextCheckColumn).Value)
  26.                 PreviousCheckDate = CDate(.Cells(CurentRow, DateCheckColumn).Value)
  27.                 dayToNextCheck = NextCheckDate - PreviousCheckDate
  28.                 .Cells(CurentRow, DayColumn).Value = Format(dayToNextCheck, "000")
  29.                 If dayToNextCheck > 0 Then
  30.                     If dayToNextCheck <= WarningPeriod Then
  31.                         .Cells(CurentRow, DayColumn).Interior.Color = vbYellow
  32.                         NearestCheckPeriodCount = NearestCheckPeriodCount + 1
  33.                     End If
  34.                 Else
  35.                     .Cells(CurentRow, DayColumn).Interior.Color = vbRed
  36.                     ExpiredChecksPeriodCount = ExpiredChecksPeriodCount + 1
  37.                 End If
  38.             End If
  39.         DoEvents
  40.         Next CurentRow
  41.     End With
  42.     If (ExpiredChecksPeriodCount > 0 Or NearestCheckPeriodCount > 0) Then
  43.         MsgBox ("Количество подходящих сроков поверки: " & NearestCheckPeriodCount & vbNewLine & _
  44.                 "Количество просраченых сроков поверки: " & ExpiredChecksPeriodCount)
  45.     End If
  46. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement