Runtime error 9 in "How to find a date in a range with VBA ?"

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Dim lngRow As Long
Dim dteInput As Date
'Range has several dates formatted as "ddd, dd/mm/aa"
Range("G3:G10").Select

'dteInput is being copied from a cell that has "23/11/2004" as a date value
(format cell = date)
'I use Windows XP, Excel XP with Spanish settings!

With Selection
'I get a runtime error 9 here

lngRow = Cells.Find(What:=dteInput, After:=ActiveCell, LookIn:=xlFormula,
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:=False, SearchFormat:=False).Row

MsgBox "lngRowDteImport = " & lngRowDteImport, vbInformation

End With

If lngRowDteImport > 0 Then 'Import Fecha already exists in Range G3:G10!

MsgBox "Date " & CStr(dteImport) & exists", vbInformation, "Terminated"
Exit Sub

Any idea why this gives an error?

TIA
Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top