Comparison Failing

Ark68

Well-known Member
Joined
Apr 5, 2005
Messages
3,241
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:

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
8,900
Office Version
2007
Platform
Windows
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
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
51,494
Office Version
365
Platform
Windows
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.
 

Forum statistics

Threads
1,082,360
Messages
5,364,923
Members
400,815
Latest member
Joaquin Phoenix

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top