Ark68
Well-known Member
- Joined
- Mar 23, 2004
- Messages
- 4,564
- Office Version
- 365
- 2016
- Platform
- Windows
Consider this sample of data from my database:
And this code ...
The idea is to find two or more records at the same facility that start within 15 minutes of the one before it ending, to become one record. An example using the data above.
146031RIM Park Outdoor FacilitiesBeach Volleyball Court 1 has two records. The first is 6:00PM-7:15PM, and the second, is 7:15PM-8:00PM
The code is intended to merge the two records into one time period for 6:00PM-8:00PM. Basically, it involves taking the later of the end times and overwriting the end time of the first record, and eliminating all but the first.
In this case, the two records would become one:
146031RIM Park Outdoor FacilitiesBeach Volleyball Court 1 6:00PM-8:00PM
When the code completes ... this is the result:
The times are wrong. (Columns N and O). They should be 6:00PM - 8:00PM.
Is anyone able to figure out my error? Is more information needed?
Excel 2010 | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | |||
1 | Record ID$ | Date | CONTRACT | Ammnt$ | Type$ | Program$ | Customer$ | Facility$ | SubFacility$ | Facility B$ | FacType$ | Unit$ | CLASS$ | Start | End | ||
25 | 41442064 | 17-Jun-13 | 146031 | 0 | CR | CARL Beach Volleyball 2013 | RIM Customer Service | RIM Park Outdoor Facilities | Beach Volleyball Court 1 | RIM Park Outdoor FacilitiesBeach Volleyball Court 1 | Court | 1 | B | 6:00 PM | 7:15 PM | ||
26 | 41442064 | 17-Jun-13 | 146031 | 0 | CR | CARL Beach Volleyball 2013 | RIM Customer Service | RIM Park Outdoor Facilities | Beach Volleyball Court 1 | RIM Park Outdoor FacilitiesBeach Volleyball Court 1 | Court | 1 | B | 7:15 PM | 8:00 PM | ||
27 | 41442065 | 17-Jun-13 | 146031 | 0 | CR | CARL Beach Volleyball 2013 | RIM Customer Service | RIM Park Outdoor Facilities | Beach Volleyball Court 2 | RIM Park Outdoor FacilitiesBeach Volleyball Court 2 | Court | 2 | B | 6:00 PM | 7:15 PM | ||
28 | 41442065 | 17-Jun-13 | 146031 | 0 | CR | CARL Beach Volleyball 2013 | RIM Customer Service | RIM Park Outdoor Facilities | Beach Volleyball Court 2 | RIM Park Outdoor FacilitiesBeach Volleyball Court 2 | Court | 2 | B | 7:15 PM | 8:00 PM | ||
29 | 41442066 | 17-Jun-13 | 146031 | 0 | CR | CARL Beach Volleyball 2013 | RIM Customer Service | RIM Park Outdoor Facilities | Beach Volleyball Court 3 | RIM Park Outdoor FacilitiesBeach Volleyball Court 3 | Court | 3 | B | 6:00 PM | 7:15 PM | ||
30 | 41442066 | 17-Jun-13 | 146031 | 0 | CR | CARL Beach Volleyball 2013 | RIM Customer Service | RIM Park Outdoor Facilities | Beach Volleyball Court 3 | RIM Park Outdoor FacilitiesBeach Volleyball Court 3 | Court | 3 | B | 7:15 PM | 8:00 PM | ||
31 | 41442067 | 17-Jun-13 | 146031 | 0 | CR | CARL Beach Volleyball 2013 | RIM Customer Service | RIM Park Outdoor Facilities | Beach Volleyball Court 4 | RIM Park Outdoor FacilitiesBeach Volleyball Court 4 | Court | 4 | B | 7:15 PM | 8:00 PM | ||
32 | 41442067 | 17-Jun-13 | 146031 | 0 | CR | CARL Beach Volleyball 2013 | RIM Customer Service | RIM Park Outdoor Facilities | Beach Volleyball Court 4 | RIM Park Outdoor FacilitiesBeach Volleyball Court 4 | Court | 4 | B | 7:15 PM | 8:00 PM | ||
Sheet1 |
And this code ...
Code:
With wshhold
If .FilterMode Then .ShowAllData
lr = .Range("A" & .Rows.Count).End(xlUp).Row
With .Range("CT2:CT" & lr)
.Formula = "=IF($CS3<>$CS2, 0, IF(ABS($N3-$O2)<=TIME(0,15,0), ""DUP"", 0))"
.Value = .Value
End With
For Rw = lr To 2 Step -1 '!!!!! WATCH THIS LINE !!!!!
If .Range("CT" & Rw) = "DUP" Then
.Range("O" & Rw - 1).Value = .Range("O" & Rw).Value
lmrg = lmrg + 1
End If
Next Rw
With .Range("CT3:CT" & lr)
On Error Resume Next
.SpecialCells(xlConstants, 2).EntireRow.Delete xlShiftUp
.Clear
End With
MsgBox lmrg & " records merged."
wshvar.Range("A37").Value = lmrg
If .FilterMode Then .ShowAllData
End With
The idea is to find two or more records at the same facility that start within 15 minutes of the one before it ending, to become one record. An example using the data above.
146031RIM Park Outdoor FacilitiesBeach Volleyball Court 1 has two records. The first is 6:00PM-7:15PM, and the second, is 7:15PM-8:00PM
The code is intended to merge the two records into one time period for 6:00PM-8:00PM. Basically, it involves taking the later of the end times and overwriting the end time of the first record, and eliminating all but the first.
In this case, the two records would become one:
146031RIM Park Outdoor FacilitiesBeach Volleyball Court 1 6:00PM-8:00PM
When the code completes ... this is the result:
Excel 2010 | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | |||
25 | 41442064 | 17-Jun-13 | 146031 | 0 | CR | CARL Beach Volleyball 2013 | RIM Customer Service | RIM Park Outdoor Facilities | Beach Volleyball Court 1 | RIM Park Outdoor FacilitiesBeach Volleyball Court 1 | Court | 1 | B | 7:15 PM | 7:15 PM | ||
26 | 41442065 | 17-Jun-13 | 146031 | 0 | CR | CARL Beach Volleyball 2013 | RIM Customer Service | RIM Park Outdoor Facilities | Beach Volleyball Court 2 | RIM Park Outdoor FacilitiesBeach Volleyball Court 2 | Court | 2 | B | 7:15 PM | 7:15 PM | ||
27 | 41442066 | 17-Jun-13 | 146031 | 0 | CR | CARL Beach Volleyball 2013 | RIM Customer Service | RIM Park Outdoor Facilities | Beach Volleyball Court 3 | RIM Park Outdoor FacilitiesBeach Volleyball Court 3 | Court | 3 | B | 7:15 PM | 7:15 PM | ||
28 | 41442067 | 17-Jun-13 | 146031 | 0 | CR | CARL Beach Volleyball 2013 | RIM Customer Service | RIM Park Outdoor Facilities | Beach Volleyball Court 4 | RIM Park Outdoor FacilitiesBeach Volleyball Court 4 | Court | 4 | B | 7:15 PM | 8:00 PM | ||
HOLDING |
The times are wrong. (Columns N and O). They should be 6:00PM - 8:00PM.
Is anyone able to figure out my error? Is more information needed?