Formula to Expel Certian Rows of Data Failing . Something wrong with my comparitors

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,564
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Please consider this snippit of code:

Rich (BB code):
                            For p = 5 To 14
                                ctime = ws_sbase.Range("B" & p) 'shift start time
                                dtime = dpgo 'preferred groom time (start time - 1 hr)
                                If Round(ctime, 5) >= Round(dtime, 5) Then
                                    If CDate(ws_sbase.Cells(p, 2)) >= CDate(dpgo) Then 
                                        ws_sbase.Range("B" & p & ":C" & p).ClearContents
                                        ws_sbase.Range("D" & p) = "X"
                                        ws_sbase.Range("E" & p) = ""
                                    End If
                                End If
                            Next p

The table below shows the different employee shifts. If an employee's shift is after the preferred service time, that shift is ineligible, and cells B, C and e are blanked out, and an X put in cell D. Those shifts which start at or before the preferred service time, are eligible and no change is made.

SO in my example, the preferred service time is 7:00AM. From the shift chart below, shifts at row 5, 6, 7, 8, 10 and 12 are eligible, and should remain untouched in the dataset. All others are cleared due to ineligibility.

But withmy current code, none are eligible. :( All the rows are beingblanked out.

Is anyone able to suggest what I need to do to ensure the results I am looking for ...


Cell Formulas
RangeFormula
A5CWP
A6CRP
A7CUE
A8HPE
A9HPL
A10RPE
A11RPL
A12WPE
A13WPL
A14CUL
B50.291666666666667
B60.291666666666667
B70.291666666666667
B80.291666666666667
B90.5625
B100.291666666666667
B110.583333333333333
B120.291666666666667
B130.5625
B140.666666666666667
C50.625
C60.625
C70.604166666666667
C80.604166666666667
C90.895833333333333
C100.604166666666667
C110.916666666666667
C120.604166666666667
C130.895833333333333
C140
D5X
D6X
D75
D8C
D9B
D10C
D11B
D12C
D13B
D146
E51
E62
E73
E84
E95
E106
E117
E128
E139
E1410



ctime = employee's shift start time (7:00 AM [0.291666667])
dtime = preferred service time, which is the program start time minus 1 hour. eg program start time = 8:00AM, dtime = 7:00AM (0.291666667)

If the shift time is greater than or equal to the service time ...
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
If I change the shift start times in the database to 6:30 AM, it all works OK.
 
Upvote 0
This worked for me

Code:
Sub aTest()
    Dim ws_sbase As Worksheet, p As Long
    Dim ctime As Double, dpgo As Double
        
    Set ws_sbase = Sheets("SBASE")
    dpgo = TimeSerial(7, 0, 0) 'preferred start time = 7 AM
    
    For p = 5 To 14
        ctime = ws_sbase.Range("B" & p) 'shift start time
        If Round(ctime, 5) > Round(dpgo, 5) Then
            ws_sbase.Range("B" & p & ":C" & p).ClearContents
            ws_sbase.Range("D" & p) = "X"
            ws_sbase.Range("E" & p) = ""
        End If
    Next p
End Sub

M.
 
Upvote 0

Forum statistics

Threads
1,215,639
Messages
6,125,971
Members
449,276
Latest member
surendra75

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top