Посчитать время вне диапазона в диапазоне дат - PullRequest
0 голосов
/ 30 октября 2019

Чтобы сохранить новый вопрос отдельно от предыдущего, я задаю его как другой вопрос.

Из приведенной ниже информации (все в столбце A) я хотел бы иметь возможность подсчитать, сколько вызововприйти на дату вне времени (или между временами). Например, сколько звонков на 8/01/2019, где НЕ с 07:00 до 23:00, используя первый набор номеров, например: 6: 47

Форматирование моего исходного файла испорчено, ноцифры ниже представляют:

Ср 30 октября 11:42:11 2019 Место: Некоторые. Место Страница 1

Call Details by Date and Time

Call Date: 01/01/2019
____________________________________________________________________________________________________________________________________________________
Start Costed   Call       Call        Access Dialed Number               Call Cost  Call          Real     Authorization   Account Code Billing Code
Time  Duration Origin     Destination  Code                                         Charge     Extension       Code                                 
_____ ________ __________ ___________ ______ ___________________________ __________ __________ __________ ________________ ____________ ____________
 1:24 00:05:12      34320      34312                               34312      $0.00      $0.00      34320                                           
11:11 00:02:46      33314      34312                               34312      $0.00      $0.00      33314                                           
19:41 00:00:50      36424      34312                               34312      $0.00      $0.00      36424                                           
20:07 00:03:28      34227      34312                               34312      $0.00      $0.00      34227                                           
21:06 00:09:00      36335      34312                               34312      $0.00      $0.00      36335                                           
21:34 00:01:54      37641      34312                               34312      $0.00      $0.00      37641                                           
Wed Oct 30 11:42:11 2019   Location: Some. Place                        Page 2

          Call Details by Date and Time

Call Date: 01/02/2019
____________________________________________________________________________________________________________________________________________________
Start Costed   Call       Call        Access Dialed Number               Call Cost  Call          Real     Authorization   Account Code Billing Code
Time  Duration Origin     Destination  Code                                         Charge     Extension       Code                                 
_____ ________ __________ ___________ ______ ___________________________ __________ __________ __________ ________________ ____________ ____________
 4:15 00:09:00      36335      34312                               34312      $0.00      $0.00      36335                                           
 4:46 00:03:30      32970      34312                               34312      $0.00      $0.00      32970                                           
 7:12 00:00:54      33022      34312                               34312      $0.00      $0.00      33022                                           
 7:21 00:03:04      33655      34312                               34312      $0.00      $0.00      33655                                           
21:02 00:00:24      33277      34312                               34312      $0.00      $0.00      33277                                           
21:19 00:02:44      37606      34312                               34312      $0.00      $0.00      37606                                           
Wed Oct 30 11:42:11 2019   Location: Some. Place                        Page 3

          Call Details by Date and Time

Call Date: 01/03/2019
____________________________________________________________________________________________________________________________________________________
Start Costed   Call       Call        Access Dialed Number               Call Cost  Call          Real     Authorization   Account Code Billing Code
Time  Duration Origin     Destination  Code                                         Charge     Extension       Code                                 
_____ ________ __________ ___________ ______ ___________________________ __________ __________ __________ ________________ ____________ ____________
 5:52 00:01:26      33322      34312                               34312      $0.00      $0.00      33322                                           
 8:09 00:05:50      34229      34312                               34312      $0.00      $0.00      34229                                           
 9:28 00:02:48      33952      34312                               34312      $0.00      $0.00      33952                                           

Вт Сен 10 08:52:40 2019 Местоположение: Страница 4

Так что этот код предназначен для того, чтобы подсчитать все звонки на дату (между "Дата звонка "и" Местоположение "от @Plutian, и она работает хорошо!

Sub counter()
Dim cel As Range
Dim i As Integer
Dim lastr As Integer
Dim calldate As String

i = 0
lastr = Sheet1.Range("A" & Rows.Count).End(xlUp).Row 'determine last row of data

For Each cel In Sheet1.Range("A1:A" & lastr) 'start loop

If InStr(cel.Value, "Call Date") Then 'check if your value is "Call date" indicating start of data
    If calldate = "" Then 'check if this is the first loop
        calldate = cel.Value 'set calldate to the current loop.
            Else 'if not first loop, write the current calldate + counter to the next available blank cell
            Range("B" & Rows.Count).End(xlUp).Offset(1, 0).Value = calldate & " " & i
            i = 0 'reste counter
            calldate = cel.Value 'save next calldate value
    End If
    Else
        If cel <> "" Then 'test if cell is blank, skip if it is
            If InStr(cel, "Location") Then 'test if cell holds "Location, indicating it is not data. Skip if it is
                Else
                i = i + 1 'increase counter if part of data
            End If
        End If
End If
Next cel
Range("B" & Rows.Count).End(xlUp).Offset(1, 0).Value = calldate & " " & I & " calls" 'Write current data at end of loop.
End Sub

Выходные данные должны быть: (Следующий неиспользуемый столбец)

Дата звонка: 08/01/2019 звонки снаружидиапазона 1

Дата звонка: 08/02/2019 звонки вне диапазона 0

Дата звонка: 08/03/2019 звонки вне диапазона 2

Спасибо всем!

1 Ответ

0 голосов
/ 31 октября 2019

Поскольку мой код для начала, его было легко адаптировать к вашим потребностям.

То, что я здесь сделал, добавил второй счетчик, который увеличивается каждый раз, когда попадание обнаруживается за пределами указанного времени. Чтобы было проще, я объединил два результата, чтобы вам не пришлось жертвовать ни одним из них.

Sub counter()
Dim cel As Range
Dim i As Integer, j As Integer
Dim lastr As Integer
Dim calldate As String

i = 0
lastr = Sheet1.Range("A" & Rows.Count).End(xlUp).Row 'determine last row of data

For Each cel In Sheet1.Range("A1:A" & lastr) 'start loop

If InStr(cel.Value, "Call Date") Then 'check if your value is "Call date" indicating start of data
    If calldate = "" Then 'check if this is the first loop
        calldate = cel.Value 'set calldate to the current loop.
            Else 'if not first loop, write the current calldate + both counters to the next available blank cell
            Range("B" & Rows.Count).End(xlUp).Offset(1, 0).Value = calldate & " " & i & " calls, of which " & j & " outside hours"
            i = 0 'reset counter
            j = 0 'reset counter
            calldate = cel.Value 'save next calldate value
    End If
    Else
        If cel <> "" Then 'test if cell is blank, skip if it is
         If IsDate(Left(cel.Value, 5)) Then 'test if first 5 characters of cell is a valid time.
                If TimeValue(Left(cel.Value, 5)) < "07:00:00" Or TimeValue(Left(cel.Value, 5)) > "23:00:00" Then 'test if call is earlier than 07:00 or later than 23:00
                    j = j + 1 'increase counter if outside that time
                End If
                i = i + 1 'increase counter if part of data
            End If
        End If
End If
Next cel
Range("B" & Rows.Count).End(xlUp).Offset(1, 0).Value = calldate & " " & i & " calls, of which " & j & " outside hours" 'Write current data at end of loop.
End Sub
...