ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Run-time error '91' on Cells.Find() (https://www.excelbanter.com/excel-programming/288482-run-time-error-91-cells-find.html)

Vera

Run-time error '91' on Cells.Find()
 
Hi,

I recorded a macro to find a date in a worksheet. The
generated code looks like this:

Range("A2").Select
Application.FindFormat.Clear
Application.FindFormat.NumberFormat = "dd/mm/yyyy"
Application.FindFormat.....
....
Cells.Find(What:="20-01-2004", After:=ActiveCell, _
LookIn:=xlValues, LookAt:=xlPart, _
SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=True).Activate

However, when I try to run this macro, I get an error
message: Run-time error '91': Object variable or With
block variable not set. When I click debug, the error
appears to be caused by the Cells.Find() statement.

My intension is to create a ThisWorkbook.Open method that
finds the current date in the worksheet.

What can I do to make this macro work?
Any help will be greatly appreciated.



All times are GMT +1. The time now is 07:30 PM.

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