I'm trying to calculate the average in column (T) with time on it (00:00:00), and exclude the rows with blank cells on column "E" and the text "PC" on column "R".
This is what I've tried so far:
It returns the run time error 6, overflow on
In this specific case, i need to average only the yellow cells.
This is what I've tried so far:
VBA Code:
Dim ws As Worksheet
Set ws = Worksheets("mapa_cargas")
Dim lastRow As Long
lastRow = ws.Cells(ws.Rows.count, "T").End(xlUp).Row
Dim totalHours As Double
totalHours = 0
Dim count2 As Long
count2 = 0
For i = 1 To lastRow
' Check if the current row contains a value to exclude
If ws.Cells(i, 5) = "" And ws.Cells(i, 18) = "" And ws.Cells(i, 20) = "" Then
totalHours = totalHours + ws.Cells(i, 20).Value * 24
count2 = count2 + 1
End If
Next i
Dim averageHours As Double
averageHours = totalHours / count2
Worksheets("indicadores").Cells(4, 7).Value = averageHours
It returns the run time error 6, overflow on
VBA Code:
averageHours = totalHours / count2
mapa.xlsm | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
E | F | G | H | I | J | R | T | |||||||||||
1 | Nº transporte | YARD CAR ID | Data Registo | Hora Registo | Espera | Hora Entrada | Cartão Motorista | Espera | ||||||||||
2 | 1951062898 | 292364 | 20.03.2023 | 07:51:01 | 01:25:08 | 09:16:09 | 01:25:08 | |||||||||||
3 | 1951062900 | 292424 | 20.03.2023 | 10:18:25 | 00:06:10 | 10:24:35 | 00:06:10 | |||||||||||
4 | 1951062902 | 292368 | 20.03.2023 | 08:24:31 | 00:10:22 | 08:34:53 | 00:10:22 | |||||||||||
5 | 1951062903 | 292383 | 20.03.2023 | 09:08:27 | 00:03:45 | 09:12:12 | 00:03:45 | |||||||||||
6 | 1951062905 | 292465 | 20.03.2023 | 14:46:04 | 02:01:49 | 16:47:53 | 02:01:49 | |||||||||||
7 | 1951062907 | 292450 | 20.03.2023 | 12:25:51 | 00:30:51 | 12:56:42 | 00:30:51 | |||||||||||
8 | 1951062910 | 292320 | 20.03.2023 | 06:37:36 | 00:07:56 | 06:45:32 | 00:07:56 | |||||||||||
9 | 1951062911 | 292318 | 20.03.2023 | 04:59:01 | 00:35:21 | 05:34:22 | 00:35:21 | |||||||||||
10 | 1951062912 | 292384 | 20.03.2023 | 09:22:08 | 00:47:43 | 10:09:51 | 00:47:43 | |||||||||||
11 | 1951062913 | 292319 | 20.03.2023 | 06:24:01 | 00:09:20 | 06:33:21 | 00:09:20 | |||||||||||
12 | 1951062919 | 292361 | 20.03.2023 | 07:19:44 | 00:27:37 | 07:47:21 | 00:27:37 | |||||||||||
13 | 1951062922 | 292365 | 20.03.2023 | 08:07:32 | 00:26:30 | 08:34:02 | 00:26:30 | |||||||||||
14 | 1951062924 | 292426 | 20.03.2023 | 10:28:20 | 00:06:52 | 10:35:12 | 00:06:52 | |||||||||||
15 | 1951062925 | 292425 | 20.03.2023 | 10:20:03 | 00:21:09 | 10:41:12 | 00:21:09 | |||||||||||
16 | 1951062926 | 292453 | 20.03.2023 | 13:16:20 | 00:10:14 | 13:26:34 | 00:10:14 | |||||||||||
17 | 1951062931 | 292362 | 20.03.2023 | 07:43:10 | 00:33:06 | 08:16:16 | 00:33:06 | |||||||||||
18 | 1951062933 | 292454 | 20.03.2023 | 13:51:40 | 00:22:09 | 14:13:49 | 00:22:09 | |||||||||||
19 | 1951062934 | 292506 | 20.03.2023 | 18:55:16 | 00:22:12 | 19:17:28 | 00:22:12 | |||||||||||
20 | 1951062935 | 292386 | 20.03.2023 | 09:23:27 | 00:16:46 | 09:40:13 | 00:16:46 | |||||||||||
21 | 1951062936 | 292467 | 20.03.2023 | 15:09:08 | 00:14:40 | 15:23:48 | 00:14:40 | |||||||||||
22 | 1951062937 | 292504 | 20.03.2023 | 19:19:54 | 00:10:22 | 19:29:16 | 00:10:22 | |||||||||||
23 | 1951062938 | 292479 | 20.03.2023 | 16:21:20 | 00:09:43 | 16:31:03 | 00:09:43 | |||||||||||
24 | 1951062939 | 292363 | 20.03.2023 | 07:46:06 | 00:29:33 | 08:15:39 | 00:29:33 | |||||||||||
25 | 1951062940 | 292417 | 20.03.2023 | 10:00:22 | 00:09:11 | 10:09:33 | 00:09:11 | |||||||||||
26 | 1951062944 | 292447 | 20.03.2023 | 11:27:14 | 00:06:17 | 11:33:31 | 00:06:17 | |||||||||||
27 | 1951062946 | 292452 | 20.03.2023 | 13:11:46 | 01:16:10 | 14:27:56 | 01:16:10 | |||||||||||
28 | 1951062952 | 292478 | 20.03.2023 | 15:59:28 | 00:30:42 | 16:30:10 | 00:30:42 | |||||||||||
29 | 1951062962 | 292456 | 20.03.2023 | 14:02:07 | 00:37:55 | 14:40:02 | 00:37:55 | |||||||||||
30 | 1951062966 | 292466 | 20.03.2023 | 14:58:41 | 00:13:17 | 15:11:58 | 00:13:17 | |||||||||||
31 | 1951062968 | 292473 | 20.03.2023 | 15:32:34 | 01:23:03 | 16:55:37 | 01:23:03 | |||||||||||
32 | 1951062974 | 292470 | 20.03.2023 | 15:14:54 | 00:28:02 | 15:42:56 | 00:28:02 | |||||||||||
33 | 1951062979 | 292492 | 20.03.2023 | 16:44:17 | 00:38:30 | 17:22:47 | 00:38:30 | |||||||||||
34 | 1951062984 | 292480 | 20.03.2023 | 16:32:38 | 00:14:48 | 16:47:26 | 00:14:48 | |||||||||||
35 | 1951062985 | 292491 | 20.03.2023 | 16:38:08 | 00:16:02 | 16:54:10 | 00:16:02 | |||||||||||
36 | 1951062988 | 292493 | 20.03.2023 | 16:48:53 | 00:31:14 | 17:20:07 | PC | 00:31:14 | ||||||||||
37 | 1951063003 | 292494 | 20.03.2023 | 16:51:24 | 01:01:17 | 17:52:41 | PC | 01:01:17 | ||||||||||
38 | 1951063008 | 292495 | 20.03.2023 | 17:16:11 | 00:38:02 | 17:54:13 | 00:38:02 | |||||||||||
39 | 1951063010 | 292497 | 20.03.2023 | 17:18:26 | 00:12:57 | 17:31:23 | 00:12:57 | |||||||||||
40 | 1951063012 | 292496 | 20.03.2023 | 17:17:17 | 00:35:44 | 17:53:01 | 00:35:44 | |||||||||||
41 | 1951063015 | 292503 | 20.03.2023 | 18:18:23 | 00:12:11 | 18:30:34 | 00:12:11 | |||||||||||
42 | 1951063017 | 292498 | 20.03.2023 | 17:29:49 | 00:35:03 | 18:04:52 | PC | 00:35:03 | ||||||||||
43 | 1951063024 | 292499 | 20.03.2023 | 17:33:53 | 00:39:23 | 18:13:16 | 00:39:23 | |||||||||||
44 | 1951063025 | 292502 | 20.03.2023 | 17:40:27 | 00:13:23 | 17:53:50 | PC | 00:13:23 | ||||||||||
45 | 1951063029 | 292500 | 20.03.2023 | 17:36:29 | 00:16:56 | 17:53:25 | 00:16:56 | |||||||||||
46 | 1951063054 | 292505 | 20.03.2023 | 18:34:13 | 00:20:49 | 18:55:02 | 00:20:49 | |||||||||||
47 | ||||||||||||||||||
48 | 292427 | 20.03.2023 | 10:33:40 | 00:12:13 | 10:45:53 | 00:12:13 | ||||||||||||
49 | ||||||||||||||||||
50 | ||||||||||||||||||
51 | 292421 | 20.03.2023 | 10:14:27 | 04:06:01 | 14:20:28 | PC | 04:06:01 | |||||||||||
52 | 292418 | 20.03.2023 | 10:11:01 | 01:04:29 | 11:15:30 | PC | 01:04:29 | |||||||||||
53 | 292419 | 20.03.2023 | 10:12:43 | 00:52:26 | 11:05:09 | PC | 00:52:26 | |||||||||||
54 | 292423 | 20.03.2023 | 10:16:55 | 00:03:21 | 10:20:16 | 00:03:21 | ||||||||||||
55 | 292446 | 20.03.2023 | 11:22:49 | 00:07:53 | 11:30:42 | 00:07:53 | ||||||||||||
56 | 292422 | 20.03.2023 | 10:15:18 | 00:39:50 | 10:55:08 | PC | 00:39:50 | |||||||||||
57 | 292420 | 20.03.2023 | 10:13:35 | 03:52:14 | 14:05:49 | PC | 03:52:14 | |||||||||||
mapa_cargas |
Cell Formulas | ||
---|---|---|
Range | Formula | |
T2:T57 | T2 | =I2 |
In this specific case, i need to average only the yellow cells.