Comparison Failing

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,562
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I feel this should be a very easy solution, but I am finding myself struggling.

Code:
                        For p = 70 To 73
                            If tpgo = "<" Then
                                pdd = format(ws_sbase.Cells(p, 2), "h:mm am/pm")
                                If pdd > 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
                            End If
                        Next p

The idea is to compare variable pdd (time) to the value in column B of a range defined by B70:E73. Sadly, I don't have an HTML generator installed to show you the data.

Within the range:
B70 = 7:00 am (pdd = 7:00 am)
B71 = 7:00 am (pdd = 7:00 am)
B72 = 7:00 am (pdd = 7:00 am)
B73 = 4:00 pm (pdd = 4:00 pm)

CDate(dpgo) = 7:00 am

This code seems to be inappropriately (based on my goal) to be eliminating all including those where pdd matches cdate(dpgo). The only range that should be affected because pdd is greater than CDate(dpgo) would be row 73 4:00 pm > 7:00 am. Rows 70-72 shouldn't be affected.
 
Last edited:

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
I feel this should be a very easy solution, but I am finding myself struggling.

Rich (BB code):
                        For p = 70 To 73
                            If tpgo = "<" Then
                                pdd = CDate(format(ws_sbase.Cells(p, 2), "h:mm am/pm"))
                                If pdd > 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
                            End If
                        Next p

Maybe, converting the text from pdd to date so that it is compared date with date
 
Upvote 0
Regarding this section here:
Code:
 For p = 70 To 73
     If tpgo = "<" Then
since it appears that "tpgo" is not changing within that loop, I think it would be more efficient to "flip" these two lines, as if "tpgo" does not equal "<", you should have to go through the loop 4 times, to do nothing.
 
Upvote 0

Forum statistics

Threads
1,213,522
Messages
6,114,112
Members
448,549
Latest member
brianhfield

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