[英]Count time outside of range in a range of dates
In order keep a new question separate from previous I'm asking it as another question.为了使新问题与以前的问题分开,我将其作为另一个问题提出。
From the info below (all in column A), I'd like to be able to count how many calls come in on a date outside of a time (or between times).从下面的信息(全部在 A 列中),我希望能够计算在某个时间之外(或时间之间)的日期有多少电话打进来。 For example, how many calls on 08/01/2019 where NOT from 07:00 to 23:00 using the first set of numbers ie: 6:47
例如,在 2019 年 8 月 1 日有多少电话不是从 07:00 到 23:00 使用第一组数字,即:6:47
The formatting of my source file is messed up, but the numbers below represent:我的源文件的格式搞砸了,但下面的数字代表:
Wed Oct 30 11:42:11 2019 Location: Some. 2019 年 10 月 30 日星期三 11:42:11 地点:一些。 Place Page 1
地点第 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
Tue Sep 10 08:52:40 2019 Location: Page 4 2019 年 9 月 10 日星期二 08:52:40 位置:第 4 页
So this code is for a way to count all of the calls on a date (between "Call Date" and "Location" from @Plutian and it works well!因此,此代码用于计算某个日期的所有呼叫(在 @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
Output hoped to be: (Next unused column) Output 希望是:(下一个未使用的列)
Call Date: 08/01/2019 calls outside of range 1通话日期:08/01/2019 通话超出范围 1
Call Date: 08/02/2019 calls outside of range 0通话日期:08/02/2019 通话超出范围 0
Call Date: 08/03/2019 calls outside of range 2通话日期:08/03/2019 通话超出范围 2
Thanks all!谢谢大家!
As it is my code to begin with, it was easy to adapt to your needs.由于这是我的代码,因此很容易适应您的需求。
What I have done here is added a second counter that increases each time a hit is found outside the times specified.我在这里所做的是添加了第二个计数器,每次在指定的时间之外发现命中时,该计数器就会增加。 To make it easier I've concatenated the two results so you don't have to sacrifice either one.
为了更容易,我将两个结果连接起来,这样你就不必牺牲任何一个。
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.