Ark68
Well-known Member
- Joined
- Mar 23, 2004
- Messages
- 4,616
- Office Version
- 365
- 2016
- Platform
- Windows
I am having problems getting this code to return the results expected.
Here is the databasethat this code is working with:
CDate(dpgo) in my testing = 7:00:00 AM
The code steps through each cell in range B38:B47 comparing the time in that cell with the time value of dpgo. If the time in cell B is greater than dpgo, that crew is excluded ad the cells B:D are cleared. All the others remain.
If this code was working, B41:D41, B45:D47 would be blanked out as the time value in B > dpgo. The others are = dpgo.
But in my testing, this code will blank the entire range.
Is anyone able to suggest why this is giving me the wrong results.
Code:
For P = 38 To 47
If ws_sbase.Range("B" & P) > CDate(dpgo) Then 'those that start before groom offset time, when the only program, is eligible
ws_sbase.Range("B" & P & ":C" & P).ClearContents
ws_sbase.Range("D" & P) = "X"
ws_sbase.Range("E" & P) = ""
End If
Next P
Here is the databasethat this code is working with:
Excel 2010 | |||||||
---|---|---|---|---|---|---|---|
A | B | C | D | E | |||
37 | RP | ||||||
38 | CRP | 7:00 AM | 3:00 PM | X | 1 | ||
39 | CWP | 7:00 AM | 3:00 PM | X | 2 | ||
40 | RPE | 7:00 AM | 3:00 PM | B | 3 | ||
41 | RPL | 1:30 PM | 9:30 PM | A | 4 | ||
42 | HPE | 7:00 AM | 3:00 PM | B | 5 | ||
43 | WPE | 7:00 AM | 3:00 PM | B | 6 | ||
44 | CUE | 7:00 AM | 3:00 PM | 5 | 7 | ||
45 | HPL | 1:30 PM | 9:30 PM | A | 8 | ||
46 | WPL | 1:30 PM | 9:30 PM | A | 9 | ||
47 | CUL | 4:00 PM | 12:00 AM | 6 | 10 | ||
SBASE |
CDate(dpgo) in my testing = 7:00:00 AM
The code steps through each cell in range B38:B47 comparing the time in that cell with the time value of dpgo. If the time in cell B is greater than dpgo, that crew is excluded ad the cells B:D are cleared. All the others remain.
If this code was working, B41:D41, B45:D47 would be blanked out as the time value in B > dpgo. The others are = dpgo.
But in my testing, this code will blank the entire range.
Is anyone able to suggest why this is giving me the wrong results.