ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Problem comparing dates (https://www.excelbanter.com/excel-programming/410242-problem-comparing-dates.html)

Ed[_30_]

Problem comparing dates
 
I have frequent problems with dates in Excel.

I declared "dat" as a date so,
"dim dat as date"

I loaded it with a value from a column of dates in "tlSht" so,
"dat=tkSht.Cells(r, 1)"

I then tried to find the same date in a column of dates in "mst:Sht" so,
"Set c = mstSht.Columns("A").Find(what:=dat)"

The above works only if both date columns are formatted in the same date
format and that is not feasible in my situation. I also tried using a
"string" and "double" variable instead of "date", but neither worked.

Can someone set me straight with this problem? Thanks!




Office_Novice

Problem comparing dates
 
Try Somthing like this

Sub newone()

Dim dat As Date
Dim fnd As Range
Dim i As Variant

dat = Worksheets("Sheet1").Range("A1")
Set fnd = Columns("B").Find(What:=dat) ' Change to your range
For Each i In fnd
If i = dat Then
MsgBox "I Found " & i '<--- Put whatever you want here
ElseIf i < Date Then
End If
Next i
End Sub


"Ed" wrote:

I have frequent problems with dates in Excel.

I declared "dat" as a date so,
"dim dat as date"

I loaded it with a value from a column of dates in "tlSht" so,
"dat=tkSht.Cells(r, 1)"

I then tried to find the same date in a column of dates in "mst:Sht" so,
"Set c = mstSht.Columns("A").Find(what:=dat)"

The above works only if both date columns are formatted in the same date
format and that is not feasible in my situation. I also tried using a
"string" and "double" variable instead of "date", but neither worked.

Can someone set me straight with this problem? Thanks!





ward376

Problem comparing dates
 
Are all the dates formatted as dates? Not the same formatting, but any
date format?

Cliff Edwards

Ed[_30_]

Problem comparing dates
 
Cliff,
That's correct - all are formatted as dates. In working with this problem it
appeared to me that they all needed to have the same date format in order to
work.


"ward376" wrote in message
...
Are all the dates formatted as dates? Not the same formatting, but any
date format?

Cliff Edwards





All times are GMT +1. The time now is 11:26 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com