ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Problem with VBA "Find" operation (https://www.excelbanter.com/excel-programming/318999-problem-vba-find-operation.html)

Don Rouse

Problem with VBA "Find" operation
 
My code (which follows) will not find a matching date.

Partial code:

"With Worksheets(myProject).Columns("AC")
Set FindClose = .Find(myCloseDate, LookIn:=xlValues)"

"myCloseDate" is a date and looks like "3/31/05".

In column "AC" is a formula that returns a date. The formula is:

=EOMONTH(Q119,0)

"FindClose" always comes up equal to "nothing". But there is a matching
date in column "AC".

What am I doing wrong?

Thank you for your assistance.

Don

Don Rouse

Problem with VBA "Find" operation
 
Dave,

Thank you for responding.

I kept playing with the problem and found another solution. If you format
the date column to exactly match the "FindWhat" date, it works. The format,
in my case, needed to be m/d/yyyy rather than my usual choice of m/d/yy.

I'll keep your solution in mind.

Thanks again.

Don

"Dave D-C" wrote:

Don wrote:
My code (which follows) will not find a matching date.
Partial code:
"With Worksheets(myProject).Columns("AC")
Set FindClose = .Find(myCloseDate, LookIn:=xlValues)"
"myCloseDate" is a date and looks like "3/31/05".
In column "AC" is a formula that returns a date. The formula is:
=EOMONTH(Q119,0)
"FindClose" always comes up equal to "nothing". But there is a matching
date in column "AC".


I get the same result. What does work is using a string variable
in the FIND statement. Which doesn't match the help info.

Sub sub1()
Dim MyCloseDate As Date, FindClose As Range
Dim zString$
Range("A5") = "3/31/05"
MyCloseDate = "3/31/05"
With Worksheets("sheet1").Columns("A")
Set FindClose = .Find(MyCloseDate, LookIn:=xlValues)
If FindClose Is Nothing Then
MsgBox "1st: Nothing"
Else
MsgBox "1st: " & FindClose.Address
End If
zString = MyCloseDate
Set FindClose = .Find(zString, LookIn:=xlValues)
If FindClose Is Nothing Then
MsgBox "2nd: Nothing"
Else
MsgBox "2nd: " & FindClose.Address
End If
End With
End Sub

--------
Sorry about the newsfeeds promos


----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---


-----------== Posted via Newsfeed.Com - Uncensored Usenet News ==----------
http://www.newsfeed.com The #1 Newsgroup Service in the World!
-----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =-----



All times are GMT +1. The time now is 12:33 PM.

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