Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

comparing dates with vba, urgent!

Status
Not open for further replies.

autex

Technical User
Jan 11, 2005
75
US
I'm having trouble getting my dates to compare correctly.

Dim dt As String
dt = Format(InputBox("Enter Date"), "mm/dd/yyyy")

For a = lastrowa To 1 Step -1
If (Sheets("active Prior YE").Cells(a, 11)) < dt Then
Rows.EntireRow(a).Interior.Color = RGB(255, 255, 0)
End If
Next a

This code is not highlighting rows with dates that are <dt
The formatting of the cells is *d/mm/yyyy.

Thanks in advace.
 

The formatting of the cells does not matter. If the cells have dates, you won't have any success comparing with a string.

You need to Dim dt as a Date and convert the user's input from a string to a date.

 
Hi,

If you have REAL DATES in your worksheet, this code will never work, cuz, REAL DATES are NUMBERS. You'll need to convert your dates to string or your string to a date.

You need to compare apples to apples...
Code:
    Dim dt As Date, a
    dt = Format(InputBox("Enter Date"), "mm/dd/yyyy")



Skip,

[glasses] [red]Be advised:[/red] Researchers have found another Descartes trueism, "Cogito ergo spud."
"I think; therefore, I YAM!
[tongue]
 
Thanks for your suggestion, would you mind telling me how you would do it. The two methods below highlight every row.

Dim dt As Date

dt = InputBox("Enter Date")
MsgBox dt

Dim dt As Date

dt = DateValue(InputBox("Enter Date"))
MsgBox dt
 
Skip, this is what I originally tried it highlights all rows. I don't have the comma a what is the comma a?
 
my bad, my bad, my bad. We are always a year behind with the work we are doing. I was comparing the wrong year every single time. It was highlighting all rows because it was supposed to. STUPID!!!!

Thanks for helping.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top